mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
api/types: move CopyToContainerOptions to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -12,13 +12,6 @@ import (
|
||||
units "github.com/docker/go-units"
|
||||
)
|
||||
|
||||
// CopyToContainerOptions holds information
|
||||
// about files to copy into a container
|
||||
type CopyToContainerOptions struct {
|
||||
AllowOverwriteDirWithFile bool
|
||||
CopyUIDGID bool
|
||||
}
|
||||
|
||||
// EventsOptions holds parameters to filter events with.
|
||||
type EventsOptions struct {
|
||||
Since string
|
||||
|
||||
@@ -22,3 +22,10 @@ type PathStat struct {
|
||||
Mtime time.Time `json:"mtime"`
|
||||
LinkTarget string `json:"linkTarget"`
|
||||
}
|
||||
|
||||
// CopyToContainerOptions holds information
|
||||
// about files to copy into a container
|
||||
type CopyToContainerOptions struct {
|
||||
AllowOverwriteDirWithFile bool
|
||||
CopyUIDGID bool
|
||||
}
|
||||
|
||||
@@ -85,3 +85,9 @@ type ContainersPruneReport = container.PruneReport
|
||||
//
|
||||
// Deprecated: use [container.PathStat].
|
||||
type ContainerPathStat = container.PathStat
|
||||
|
||||
// CopyToContainerOptions holds information
|
||||
// about files to copy into a container.
|
||||
//
|
||||
// Deprecated: use [container.CopyToContainerOptions],
|
||||
type CopyToContainerOptions = container.CopyToContainerOptions
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
)
|
||||
|
||||
@@ -31,7 +30,7 @@ func (cli *Client) ContainerStatPath(ctx context.Context, containerID, path stri
|
||||
|
||||
// CopyToContainer copies content into the container filesystem.
|
||||
// Note that `content` must be a Reader for a TAR archive
|
||||
func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options types.CopyToContainerOptions) error {
|
||||
func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options container.CopyToContainerOptions) error {
|
||||
query := url.Values{}
|
||||
query.Set("path", filepath.ToSlash(dstPath)) // Normalize the paths used in the API.
|
||||
// Do not allow for an existing directory to be overwritten by a non-directory and vice versa.
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"gotest.tools/v3/assert"
|
||||
@@ -98,7 +97,7 @@ func TestCopyToContainerError(t *testing.T) {
|
||||
client := &Client{
|
||||
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
|
||||
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), container.CopyToContainerOptions{})
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
|
||||
}
|
||||
|
||||
@@ -106,7 +105,7 @@ func TestCopyToContainerNotFoundError(t *testing.T) {
|
||||
client := &Client{
|
||||
client: newMockClient(errorMock(http.StatusNotFound, "Not found")),
|
||||
}
|
||||
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
|
||||
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), container.CopyToContainerOptions{})
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
|
||||
}
|
||||
|
||||
@@ -116,7 +115,7 @@ func TestCopyToContainerEmptyResponse(t *testing.T) {
|
||||
client := &Client{
|
||||
client: newMockClient(errorMock(http.StatusNoContent, "No content")),
|
||||
}
|
||||
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
|
||||
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), container.CopyToContainerOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -160,7 +159,7 @@ func TestCopyToContainer(t *testing.T) {
|
||||
}, nil
|
||||
}),
|
||||
}
|
||||
err := client.CopyToContainer(context.Background(), "container_id", expectedPath, bytes.NewReader([]byte("content")), types.CopyToContainerOptions{
|
||||
err := client.CopyToContainer(context.Background(), "container_id", expectedPath, bytes.NewReader([]byte("content")), container.CopyToContainerOptions{
|
||||
AllowOverwriteDirWithFile: false,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -76,7 +76,7 @@ type ContainerAPIClient interface {
|
||||
ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error)
|
||||
ContainerWait(ctx context.Context, container string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
|
||||
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, container.PathStat, error)
|
||||
CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
|
||||
CopyToContainer(ctx context.Context, container, path string, content io.Reader, options container.CopyToContainerOptions) error
|
||||
ContainersPrune(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error)
|
||||
}
|
||||
|
||||
|
||||
@@ -1188,7 +1188,7 @@ func (s *DockerAPISuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRoot
|
||||
apiClient, err := client.NewClientWithOpts(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
|
||||
err = apiClient.CopyToContainer(testutil.GetContext(c), cID, "/vol2/symlinkToAbsDir", nil, types.CopyToContainerOptions{})
|
||||
err = apiClient.CopyToContainer(testutil.GetContext(c), cID, "/vol2/symlinkToAbsDir", nil, container.CopyToContainerOptions{})
|
||||
assert.ErrorContains(c, err, "container rootfs is marked read-only")
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
@@ -54,7 +55,7 @@ func TestCopyToContainerPathDoesNotExist(t *testing.T) {
|
||||
apiClient := testEnv.APIClient()
|
||||
cid := container.Create(ctx, t, apiClient)
|
||||
|
||||
err := apiClient.CopyToContainer(ctx, cid, "/dne", nil, types.CopyToContainerOptions{})
|
||||
err := apiClient.CopyToContainer(ctx, cid, "/dne", nil, containertypes.CopyToContainerOptions{})
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
|
||||
assert.Check(t, is.ErrorContains(err, "Could not find the file /dne in container "+cid))
|
||||
}
|
||||
@@ -67,17 +68,17 @@ func TestCopyEmptyFile(t *testing.T) {
|
||||
|
||||
// empty content
|
||||
dstDir, _ := makeEmptyArchive(t)
|
||||
err := apiClient.CopyToContainer(ctx, cid, dstDir, bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
|
||||
err := apiClient.CopyToContainer(ctx, cid, dstDir, bytes.NewReader([]byte("")), containertypes.CopyToContainerOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
// tar with empty file
|
||||
dstDir, preparedArchive := makeEmptyArchive(t)
|
||||
err = apiClient.CopyToContainer(ctx, cid, dstDir, preparedArchive, types.CopyToContainerOptions{})
|
||||
err = apiClient.CopyToContainer(ctx, cid, dstDir, preparedArchive, containertypes.CopyToContainerOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
// tar with empty file archive mode
|
||||
dstDir, preparedArchive = makeEmptyArchive(t)
|
||||
err = apiClient.CopyToContainer(ctx, cid, dstDir, preparedArchive, types.CopyToContainerOptions{
|
||||
err = apiClient.CopyToContainer(ctx, cid, dstDir, preparedArchive, containertypes.CopyToContainerOptions{
|
||||
CopyUIDGID: true,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
@@ -125,7 +126,7 @@ func TestCopyToContainerPathIsNotDir(t *testing.T) {
|
||||
if testEnv.DaemonInfo.OSType == "windows" {
|
||||
path = "c:/windows/system32/drivers/etc/hosts/"
|
||||
}
|
||||
err := apiClient.CopyToContainer(ctx, cid, path, nil, types.CopyToContainerOptions{})
|
||||
err := apiClient.CopyToContainer(ctx, cid, path, nil, containertypes.CopyToContainerOptions{})
|
||||
assert.Check(t, is.ErrorContains(err, "not a directory"))
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/dmesg"
|
||||
@@ -42,7 +42,7 @@ func TestNoOverlayfsWarningsAboutUndefinedBehaviors(t *testing.T) {
|
||||
{name: "cp to container", operation: func(t *testing.T) error {
|
||||
archive, err := archive.Generate("new-file", "hello-world")
|
||||
assert.NilError(t, err, "failed to create a temporary archive")
|
||||
return client.CopyToContainer(ctx, cID, "/", archive, types.CopyToContainerOptions{})
|
||||
return client.CopyToContainer(ctx, cID, "/", archive, containertypes.CopyToContainerOptions{})
|
||||
}},
|
||||
{name: "cp from container", operation: func(*testing.T) error {
|
||||
rc, _, err := client.CopyFromContainer(ctx, cID, "/file")
|
||||
|
||||
@@ -416,7 +416,7 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) {
|
||||
dstDir, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, archive.CopyInfo{Path: "/test"})
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = c.CopyToContainer(ctx, cID, dstDir, preparedArchive, types.CopyToContainerOptions{})
|
||||
err = c.CopyToContainer(ctx, cID, dstDir, preparedArchive, containertypes.CopyToContainerOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
rdr, _, err := c.CopyFromContainer(ctx, cID, "/test")
|
||||
|
||||
Reference in New Issue
Block a user