Skip to content

Commit 47d7c9e

Browse files
committed
api/types: move ContainerPathStat to api/types/container
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent db2f1ac commit 47d7c9e

13 files changed

Lines changed: 63 additions & 51 deletions

File tree

api/server/router/container/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ type execBackend interface {
2323

2424
// copyBackend includes functions to implement to provide container copy functionality.
2525
type copyBackend interface {
26-
ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error)
26+
ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *container.PathStat, err error)
2727
ContainerExport(ctx context.Context, name string, out io.Writer) error
2828
ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error
29-
ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error)
29+
ContainerStatPath(name string, path string) (stat *container.PathStat, err error)
3030
}
3131

3232
// stateBackend includes functions to implement to provide container state lifecycle functionality.

api/server/router/container/copy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"net/http"
1111

1212
"github.com/docker/docker/api/server/httputils"
13-
"github.com/docker/docker/api/types"
13+
"github.com/docker/docker/api/types/container"
1414
gddohttputil "github.com/golang/gddo/httputil"
1515
)
1616

1717
// setContainerPathStatHeader encodes the stat to JSON, base64 encode, and place in a header.
18-
func setContainerPathStatHeader(stat *types.ContainerPathStat, header http.Header) error {
18+
func setContainerPathStatHeader(stat *container.PathStat, header http.Header) error {
1919
statJSON, err := json.Marshal(stat)
2020
if err != nil {
2121
return err

api/types/container/container.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
package container
22

3+
import (
4+
"os"
5+
"time"
6+
)
7+
38
// PruneReport contains the response for Engine API:
49
// POST "/containers/prune"
510
type PruneReport struct {
611
ContainersDeleted []string
712
SpaceReclaimed uint64
813
}
14+
15+
// PathStat is used to encode the header from
16+
// GET "/containers/{name:.*}/archive"
17+
// "Name" is the file or directory name.
18+
type PathStat struct {
19+
Name string `json:"name"`
20+
Size int64 `json:"size"`
21+
Mode os.FileMode `json:"mode"`
22+
Mtime time.Time `json:"mtime"`
23+
LinkTarget string `json:"linkTarget"`
24+
}

api/types/types.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package types // import "github.com/docker/docker/api/types"
22

33
import (
44
"io"
5-
"os"
65
"time"
76

87
"github.com/docker/docker/api/types/container"
@@ -162,17 +161,6 @@ type Container struct {
162161
Mounts []MountPoint
163162
}
164163

165-
// ContainerPathStat is used to encode the header from
166-
// GET "/containers/{name:.*}/archive"
167-
// "Name" is the file or directory name.
168-
type ContainerPathStat struct {
169-
Name string `json:"name"`
170-
Size int64 `json:"size"`
171-
Mode os.FileMode `json:"mode"`
172-
Mtime time.Time `json:"mtime"`
173-
LinkTarget string `json:"linkTarget"`
174-
}
175-
176164
// ContainerStats contains response of Engine API:
177165
// GET "/stats"
178166
type ContainerStats struct {

api/types/types_deprecated.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ type ContainerExecInspect = container.ExecInspect
7878
//
7979
// Deprecated: use [container.PruneReport].
8080
type ContainersPruneReport = container.PruneReport
81+
82+
// ContainerPathStat is used to encode the header from
83+
// GET "/containers/{name:.*}/archive"
84+
// "Name" is the file or directory name.
85+
//
86+
// Deprecated: use [container.PathStat].
87+
type ContainerPathStat = container.PathStat

client/container_copy.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ import (
1212
"strings"
1313

1414
"github.com/docker/docker/api/types"
15+
"github.com/docker/docker/api/types/container"
1516
)
1617

1718
// ContainerStatPath returns stat information about a path inside the container filesystem.
18-
func (cli *Client) ContainerStatPath(ctx context.Context, containerID, path string) (types.ContainerPathStat, error) {
19+
func (cli *Client) ContainerStatPath(ctx context.Context, containerID, path string) (container.PathStat, error) {
1920
query := url.Values{}
2021
query.Set("path", filepath.ToSlash(path)) // Normalize the paths used in the API.
2122

2223
urlStr := "/containers/" + containerID + "/archive"
2324
response, err := cli.head(ctx, urlStr, query, nil)
2425
defer ensureReaderClosed(response)
2526
if err != nil {
26-
return types.ContainerPathStat{}, err
27+
return container.PathStat{}, err
2728
}
2829
return getContainerPathStatFromHeader(response.header)
2930
}
@@ -55,14 +56,14 @@ func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath str
5556

5657
// CopyFromContainer gets the content from the container and returns it as a Reader
5758
// for a TAR archive to manipulate it in the host. It's up to the caller to close the reader.
58-
func (cli *Client) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
59+
func (cli *Client) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, container.PathStat, error) {
5960
query := make(url.Values, 1)
6061
query.Set("path", filepath.ToSlash(srcPath)) // Normalize the paths used in the API.
6162

6263
apiPath := "/containers/" + containerID + "/archive"
6364
response, err := cli.get(ctx, apiPath, query, nil)
6465
if err != nil {
65-
return nil, types.ContainerPathStat{}, err
66+
return nil, container.PathStat{}, err
6667
}
6768

6869
// In order to get the copy behavior right, we need to know information
@@ -78,8 +79,8 @@ func (cli *Client) CopyFromContainer(ctx context.Context, containerID, srcPath s
7879
return response.body, stat, err
7980
}
8081

81-
func getContainerPathStatFromHeader(header http.Header) (types.ContainerPathStat, error) {
82-
var stat types.ContainerPathStat
82+
func getContainerPathStatFromHeader(header http.Header) (container.PathStat, error) {
83+
var stat container.PathStat
8384

8485
encodedStat := header.Get("X-Docker-Container-Path-Stat")
8586
statDecoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(encodedStat))

client/container_copy_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313

1414
"github.com/docker/docker/api/types"
15+
"github.com/docker/docker/api/types/container"
1516
"github.com/docker/docker/errdefs"
1617
"gotest.tools/v3/assert"
1718
is "gotest.tools/v3/assert/cmp"
@@ -64,7 +65,7 @@ func TestContainerStatPath(t *testing.T) {
6465
if path != expectedPath {
6566
return nil, fmt.Errorf("path not set in URL query properly")
6667
}
67-
content, err := json.Marshal(types.ContainerPathStat{
68+
content, err := json.Marshal(container.PathStat{
6869
Name: "name",
6970
Mode: 0o700,
7071
})
@@ -188,7 +189,7 @@ func TestCopyFromContainerNotFoundError(t *testing.T) {
188189
func TestCopyFromContainerEmptyResponse(t *testing.T) {
189190
client := &Client{
190191
client: newMockClient(func(req *http.Request) (*http.Response, error) {
191-
content, err := json.Marshal(types.ContainerPathStat{
192+
content, err := json.Marshal(container.PathStat{
192193
Name: "path/to/file",
193194
Mode: 0o700,
194195
})
@@ -242,7 +243,7 @@ func TestCopyFromContainer(t *testing.T) {
242243
return nil, fmt.Errorf("path not set in URL query properly, expected '%s', got %s", expectedPath, path)
243244
}
244245

245-
headercontent, err := json.Marshal(types.ContainerPathStat{
246+
headercontent, err := json.Marshal(container.PathStat{
246247
Name: "name",
247248
Mode: 0o700,
248249
})

client/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type ContainerAPIClient interface {
6666
ContainerRename(ctx context.Context, container, newContainerName string) error
6767
ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error
6868
ContainerRestart(ctx context.Context, container string, options container.StopOptions) error
69-
ContainerStatPath(ctx context.Context, container, path string) (types.ContainerPathStat, error)
69+
ContainerStatPath(ctx context.Context, container, path string) (container.PathStat, error)
7070
ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error)
7171
ContainerStatsOneShot(ctx context.Context, container string) (types.ContainerStats, error)
7272
ContainerStart(ctx context.Context, container string, options container.StartOptions) error
@@ -75,7 +75,7 @@ type ContainerAPIClient interface {
7575
ContainerUnpause(ctx context.Context, container string) error
7676
ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error)
7777
ContainerWait(ctx context.Context, container string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
78-
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
78+
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, container.PathStat, error)
7979
CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
8080
ContainersPrune(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error)
8181
}

container/archive_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55
"path/filepath"
66

7-
"github.com/docker/docker/api/types"
7+
containertypes "github.com/docker/docker/api/types/container"
88
"github.com/docker/docker/pkg/archive"
99
"github.com/pkg/errors"
1010
)
@@ -45,7 +45,7 @@ func (container *Container) ResolvePath(path string) (resolvedPath, absPath stri
4545
// be acquired before calling this method and the given path should be fully
4646
// resolved to a path on the host corresponding to the given absolute path
4747
// inside the container.
48-
func (container *Container) StatPath(resolvedPath, absPath string) (stat *types.ContainerPathStat, err error) {
48+
func (container *Container) StatPath(resolvedPath, absPath string) (stat *containertypes.PathStat, err error) {
4949
if container.BaseFS == "" {
5050
return nil, errors.New("StatPath: BaseFS of container " + container.ID + " is unexpectedly empty")
5151
}
@@ -72,7 +72,7 @@ func (container *Container) StatPath(resolvedPath, absPath string) (stat *types.
7272
linkTarget = filepath.Join(string(filepath.Separator), linkTarget)
7373
}
7474

75-
return &types.ContainerPathStat{
75+
return &containertypes.PathStat{
7676
Name: filepath.Base(absPath),
7777
Size: lstat.Size(),
7878
Mode: lstat.Mode(),

daemon/archive.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"io"
55
"os"
66

7-
"github.com/docker/docker/api/types"
7+
"github.com/docker/docker/api/types/container"
88
"github.com/docker/docker/errdefs"
99
)
1010

1111
// ContainerStatPath stats the filesystem resource at the specified path in the
1212
// container identified by the given name.
13-
func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error) {
13+
func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *container.PathStat, err error) {
1414
ctr, err := daemon.GetContainer(name)
1515
if err != nil {
1616
return nil, err
@@ -30,7 +30,7 @@ func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.C
3030
// ContainerArchivePath creates an archive of the filesystem resource at the
3131
// specified path in the container identified by the given name. Returns a
3232
// tar archive of the resource and whether it was a directory or a single file.
33-
func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error) {
33+
func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *container.PathStat, err error) {
3434
ctr, err := daemon.GetContainer(name)
3535
if err != nil {
3636
return nil, nil, err

0 commit comments

Comments
 (0)