зеркало из https://github.com/docker/engine-api.git
Update CopyToContainer method signature…
… to define the required arguments needed to be called. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Родитель
9b12a765bb
Коммит
6dc7afebdb
|
@ -30,17 +30,17 @@ func (cli *Client) ContainerStatPath(ctx context.Context, containerID, path stri
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyToContainer copies content into the container filesystem.
|
// CopyToContainer copies content into the container filesystem.
|
||||||
func (cli *Client) CopyToContainer(ctx context.Context, options types.CopyToContainerOptions) error {
|
func (cli *Client) CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("path", filepath.ToSlash(options.Path)) // Normalize the paths used in the API.
|
query.Set("path", filepath.ToSlash(path)) // Normalize the paths used in the API.
|
||||||
// Do not allow for an existing directory to be overwritten by a non-directory and vice versa.
|
// Do not allow for an existing directory to be overwritten by a non-directory and vice versa.
|
||||||
if !options.AllowOverwriteDirWithFile {
|
if !options.AllowOverwriteDirWithFile {
|
||||||
query.Set("noOverwriteDirNonDir", "true")
|
query.Set("noOverwriteDirNonDir", "true")
|
||||||
}
|
}
|
||||||
|
|
||||||
path := fmt.Sprintf("/containers/%s/archive", options.ContainerID)
|
apiPath := fmt.Sprintf("/containers/%s/archive", container)
|
||||||
|
|
||||||
response, err := cli.putRaw(ctx, path, query, options.Content, nil)
|
response, err := cli.putRaw(ctx, apiPath, query, content, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -55,11 +55,11 @@ func (cli *Client) CopyToContainer(ctx context.Context, options types.CopyToCont
|
||||||
|
|
||||||
// CopyFromContainer gets the content from the container and returns it as a Reader
|
// CopyFromContainer gets the content from the container and returns it as a Reader
|
||||||
// to manipulate it in the host. It's up to the caller to close the reader.
|
// to manipulate it in the host. It's up to the caller to close the reader.
|
||||||
func (cli *Client) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
|
func (cli *Client) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
|
||||||
query := make(url.Values, 1)
|
query := make(url.Values, 1)
|
||||||
query.Set("path", filepath.ToSlash(srcPath)) // Normalize the paths used in the API.
|
query.Set("path", filepath.ToSlash(srcPath)) // Normalize the paths used in the API.
|
||||||
|
|
||||||
apiPath := fmt.Sprintf("/containers/%s/archive", containerID)
|
apiPath := fmt.Sprintf("/containers/%s/archive", container)
|
||||||
response, err := cli.get(ctx, apiPath, query, nil)
|
response, err := cli.get(ctx, apiPath, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, types.ContainerPathStat{}, err
|
return nil, types.ContainerPathStat{}, err
|
||||||
|
|
|
@ -89,7 +89,7 @@ func TestCopyToContainerError(t *testing.T) {
|
||||||
client := &Client{
|
client := &Client{
|
||||||
transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
|
transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
|
||||||
}
|
}
|
||||||
err := client.CopyToContainer(context.Background(), types.CopyToContainerOptions{})
|
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
|
||||||
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
||||||
t.Fatalf("expected a Server error, got %v", err)
|
t.Fatalf("expected a Server error, got %v", err)
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ func TestCopyToContainerNotStatusOKError(t *testing.T) {
|
||||||
client := &Client{
|
client := &Client{
|
||||||
transport: newMockClient(nil, errorMock(http.StatusNoContent, "No content")),
|
transport: newMockClient(nil, errorMock(http.StatusNoContent, "No content")),
|
||||||
}
|
}
|
||||||
err := client.CopyToContainer(context.Background(), types.CopyToContainerOptions{})
|
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
|
||||||
if err == nil || err.Error() != "unexpected status code from daemon: 204" {
|
if err == nil || err.Error() != "unexpected status code from daemon: 204" {
|
||||||
t.Fatalf("expected a unexpected status code error, got %v", err)
|
t.Fatalf("expected a unexpected status code error, got %v", err)
|
||||||
}
|
}
|
||||||
|
@ -143,10 +143,8 @@ func TestCopyToContainer(t *testing.T) {
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
err := client.CopyToContainer(context.Background(), types.CopyToContainerOptions{
|
err := client.CopyToContainer(context.Background(), "container_id", expectedPath, bytes.NewReader([]byte("content")), types.CopyToContainerOptions{
|
||||||
ContainerID: "container_id",
|
AllowOverwriteDirWithFile: false,
|
||||||
Path: expectedPath,
|
|
||||||
Content: bytes.NewReader([]byte("content")),
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -44,7 +44,7 @@ type APIClient interface {
|
||||||
ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) error
|
ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) error
|
||||||
ContainerWait(ctx context.Context, container string) (int, error)
|
ContainerWait(ctx context.Context, container string) (int, error)
|
||||||
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
|
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
|
||||||
CopyToContainer(ctx context.Context, options types.CopyToContainerOptions) error
|
CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
|
||||||
Events(ctx context.Context, options types.EventsOptions) (io.ReadCloser, error)
|
Events(ctx context.Context, options types.EventsOptions) (io.ReadCloser, error)
|
||||||
ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
|
ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
|
||||||
ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error)
|
ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error)
|
||||||
|
|
|
@ -69,9 +69,6 @@ type ContainerRemoveOptions struct {
|
||||||
// CopyToContainerOptions holds information
|
// CopyToContainerOptions holds information
|
||||||
// about files to copy into a container
|
// about files to copy into a container
|
||||||
type CopyToContainerOptions struct {
|
type CopyToContainerOptions struct {
|
||||||
ContainerID string
|
|
||||||
Path string
|
|
||||||
Content io.Reader
|
|
||||||
AllowOverwriteDirWithFile bool
|
AllowOverwriteDirWithFile bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче