From e332c41e9d29954c78f927ae6b4e884fcb683cdd Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Fri, 23 Sep 2022 14:09:51 -0400 Subject: [PATCH] pkg/containerfs: alias ContainerFS to string Drop the constructor and redundant string() type-casts. Signed-off-by: Cory Snider --- .../adapters/snapshot/snapshot.go | 4 +- builder/dockerfile/copy.go | 10 ++--- builder/dockerfile/internals.go | 2 +- builder/remotecontext/archive.go | 8 ++-- builder/remotecontext/detect.go | 2 +- builder/remotecontext/detect_test.go | 4 +- builder/remotecontext/lazycontext.go | 6 +-- builder/remotecontext/tarsum.go | 4 +- builder/remotecontext/tarsum_test.go | 6 +-- container/archive.go | 2 +- container/container.go | 4 +- daemon/archive.go | 12 +++--- daemon/export.go | 4 +- daemon/graphdriver/aufs/aufs.go | 4 +- daemon/graphdriver/aufs/aufs_test.go | 32 ++++++--------- daemon/graphdriver/btrfs/btrfs.go | 2 +- daemon/graphdriver/btrfs/btrfs_test.go | 4 +- daemon/graphdriver/devmapper/driver.go | 4 +- daemon/graphdriver/fsdiff.go | 16 +++----- .../fuse-overlayfs/fuseoverlayfs.go | 6 +-- .../graphdriver/graphtest/graphbench_unix.go | 2 +- .../graphdriver/graphtest/graphtest_unix.go | 12 +++--- daemon/graphdriver/graphtest/testutil.go | 40 +++++++++---------- daemon/graphdriver/graphtest/testutil_unix.go | 10 ++--- daemon/graphdriver/overlay/overlay.go | 6 +-- daemon/graphdriver/overlay2/overlay.go | 6 +-- daemon/graphdriver/proxy.go | 2 +- daemon/graphdriver/vfs/driver.go | 4 +- daemon/graphdriver/windows/windows.go | 6 +-- daemon/graphdriver/zfs/zfs.go | 4 +- daemon/initlayer/setup_unix.go | 2 +- daemon/list_windows.go | 2 +- daemon/oci_linux.go | 2 +- daemon/oci_linux_test.go | 3 +- daemon/oci_windows.go | 2 +- .../plugin/graphdriver/external_test.go | 2 +- layer/layer_store.go | 2 +- layer/layer_test.go | 18 ++++----- layer/layer_windows.go | 2 +- layer/mount_test.go | 18 ++++----- libnetwork/ipam/structures.go | 2 +- pkg/containerfs/containerfs.go | 8 +--- plugin/manager_linux.go | 3 +- 43 files changed, 136 insertions(+), 158 deletions(-) diff --git a/builder/builder-next/adapters/snapshot/snapshot.go b/builder/builder-next/adapters/snapshot/snapshot.go index c05f441a9e..c77f7ff96f 100644 --- a/builder/builder-next/adapters/snapshot/snapshot.go +++ b/builder/builder-next/adapters/snapshot/snapshot.go @@ -291,7 +291,7 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) (snapshot.Mountabl return nil, nil, err } return []mount.Mount{{ - Source: string(rootfs), + Source: rootfs, Type: "bind", Options: []string{"rbind"}, }}, func() error { @@ -312,7 +312,7 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) (snapshot.Mountabl return nil, nil, err } return []mount.Mount{{ - Source: string(rootfs), + Source: rootfs, Type: "bind", Options: []string{"rbind"}, }}, func() error { diff --git a/builder/dockerfile/copy.go b/builder/dockerfile/copy.go index 70879d8b28..eb458a477d 100644 --- a/builder/dockerfile/copy.go +++ b/builder/dockerfile/copy.go @@ -45,7 +45,7 @@ type copyInfo struct { } func (c copyInfo) fullPath() (string, error) { - return containerfs.ResolveScopedPath(string(c.root), c.path) + return containerfs.ResolveScopedPath(c.root, c.path) } func newCopyInfoFromSource(source builder.Source, path string, hash string) copyInfo { @@ -159,7 +159,7 @@ func (o *copier) getCopyInfoForSourcePath(orig, dest string) ([]copyInfo, error) } path = unnamedFilename } - o.tmpPaths = append(o.tmpPaths, string(remote.Root())) + o.tmpPaths = append(o.tmpPaths, remote.Root()) hash, err := remote.Hash(path) ci := newCopyInfoFromSource(remote, path, hash) @@ -202,7 +202,7 @@ func (o *copier) calcCopyInfo(origPath string, allowWildcards bool) ([]copyInfo, o.source, err = remotecontext.NewLazySource(rwLayer.Root()) if err != nil { - return nil, errors.Wrapf(err, "failed to create context for copy from %s", string(rwLayer.Root())) + return nil, errors.Wrapf(err, "failed to create context for copy from %s", rwLayer.Root()) } } @@ -259,7 +259,7 @@ func (o *copier) storeInPathCache(im *imageMount, path string, hash string) { func (o *copier) copyWithWildcards(origPath string) ([]copyInfo, error) { root := o.source.Root() var copyInfos []copyInfo - if err := filepath.Walk(string(root), func(path string, info os.FileInfo, err error) error { + if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { return err } @@ -442,7 +442,7 @@ func downloadSource(output io.Writer, stdout io.Writer, srcURL string) (remote b return } - lc, err := remotecontext.NewLazySource(containerfs.NewLocalContainerFS(tmpDir)) + lc, err := remotecontext.NewLazySource(tmpDir) return lc, filename, err } diff --git a/builder/dockerfile/internals.go b/builder/dockerfile/internals.go index ce7cc38e7d..e78aa01a04 100644 --- a/builder/dockerfile/internals.go +++ b/builder/dockerfile/internals.go @@ -147,7 +147,7 @@ func (b *Builder) performCopy(req dispatchRequest, inst copyInstruction) error { // translated (if necessary because of user namespaces), and replace // the root pair with the chown pair for copy operations if inst.chownStr != "" { - identity, err = parseChownFlag(b, state, inst.chownStr, string(destInfo.root), b.idMapping) + identity, err = parseChownFlag(b, state, inst.chownStr, destInfo.root, b.idMapping) if err != nil { if b.options.Platform != "windows" { return errors.Wrapf(err, "unable to convert uid/gid chown string to host mapping") diff --git a/builder/remotecontext/archive.go b/builder/remotecontext/archive.go index 2f82d4af61..4f1fbf2d6a 100644 --- a/builder/remotecontext/archive.go +++ b/builder/remotecontext/archive.go @@ -20,7 +20,7 @@ type archiveContext struct { } func (c *archiveContext) Close() error { - return os.RemoveAll(string(c.root)) + return os.RemoveAll(c.root) } func convertPathError(err error, cleanpath string) error { @@ -53,7 +53,7 @@ func FromArchive(tarStream io.Reader) (builder.Source, error) { } // Assume local file system. Since it's coming from a tar file. - tsc := &archiveContext{root: containerfs.NewLocalContainerFS(root)} + tsc := &archiveContext{root: root} // Make sure we clean-up upon error. In the happy case the caller // is expected to manage the clean-up @@ -100,7 +100,7 @@ func (c *archiveContext) Hash(path string) (string, error) { return "", err } - rel, err := filepath.Rel(string(c.root), fullpath) + rel, err := filepath.Rel(c.root, fullpath) if err != nil { return "", convertPathError(err, cleanpath) } @@ -117,7 +117,7 @@ func (c *archiveContext) Hash(path string) (string, error) { func normalize(path string, root containerfs.ContainerFS) (cleanPath, fullPath string, err error) { cleanPath = filepath.Clean(string(filepath.Separator) + path)[1:] - fullPath, err = containerfs.ResolveScopedPath(string(root), path) + fullPath, err = containerfs.ResolveScopedPath(root, path) if err != nil { return "", "", errors.Wrapf(err, "forbidden path outside the build context: %s (%s)", path, cleanPath) } diff --git a/builder/remotecontext/detect.go b/builder/remotecontext/detect.go index f3637cf568..6fd18fbd9e 100644 --- a/builder/remotecontext/detect.go +++ b/builder/remotecontext/detect.go @@ -176,7 +176,7 @@ func StatAt(remote builder.Source, path string) (os.FileInfo, error) { // FullPath is a helper for getting a full path for a path from a source func FullPath(remote builder.Source, path string) (string, error) { - fullPath, err := containerfs.ResolveScopedPath(string(remote.Root()), path) + fullPath, err := containerfs.ResolveScopedPath(remote.Root(), path) if err != nil { if runtime.GOOS == "windows" { return "", fmt.Errorf("failed to resolve scoped path %s (%s): %s. Possible cause is a forbidden path outside the build context", path, fullPath, err) diff --git a/builder/remotecontext/detect_test.go b/builder/remotecontext/detect_test.go index f41397da91..8d514235b3 100644 --- a/builder/remotecontext/detect_test.go +++ b/builder/remotecontext/detect_test.go @@ -53,7 +53,7 @@ func checkDirectory(t *testing.T, dir string, expectedFiles []string) { } func executeProcess(t *testing.T, contextDir string) { - modifiableCtx := &stubRemote{root: containerfs.NewLocalContainerFS(contextDir)} + modifiableCtx := &stubRemote{root: contextDir} err := removeDockerfile(modifiableCtx, builder.DefaultDockerfileName) @@ -119,5 +119,5 @@ func (r *stubRemote) Close() error { return errors.New("not implemented") } func (r *stubRemote) Remove(p string) error { - return os.Remove(filepath.Join(string(r.root), p)) + return os.Remove(filepath.Join(r.root, p)) } diff --git a/builder/remotecontext/lazycontext.go b/builder/remotecontext/lazycontext.go index b5f1af876a..620671d444 100644 --- a/builder/remotecontext/lazycontext.go +++ b/builder/remotecontext/lazycontext.go @@ -66,7 +66,7 @@ func (c *lazySource) Hash(path string) (string, error) { } func (c *lazySource) prepareHash(relPath string, fi os.FileInfo) (string, error) { - p := filepath.Join(string(c.root), relPath) + p := filepath.Join(c.root, relPath) h, err := NewFileHash(p, relPath, fi) if err != nil { return "", errors.Wrapf(err, "failed to create hash for %s", relPath) @@ -91,7 +91,7 @@ func (c *lazySource) prepareHash(relPath string, fi os.FileInfo) (string, error) func Rel(basepath containerfs.ContainerFS, targpath string) (string, error) { // filepath.Rel can't handle UUID paths in windows if runtime.GOOS == "windows" { - pfx := string(basepath) + `\` + pfx := basepath + `\` if strings.HasPrefix(targpath, pfx) { p := strings.TrimPrefix(targpath, pfx) if p == "" { @@ -100,5 +100,5 @@ func Rel(basepath containerfs.ContainerFS, targpath string) (string, error) { return p, nil } } - return filepath.Rel(string(basepath), targpath) + return filepath.Rel(basepath, targpath) } diff --git a/builder/remotecontext/tarsum.go b/builder/remotecontext/tarsum.go index 67ec9100ca..6ef24f9b9e 100644 --- a/builder/remotecontext/tarsum.go +++ b/builder/remotecontext/tarsum.go @@ -28,7 +28,7 @@ type CachableSource struct { func NewCachableSource(root string) *CachableSource { ts := &CachableSource{ tree: iradix.New(), - root: containerfs.NewLocalContainerFS(root), + root: root, } return ts } @@ -67,7 +67,7 @@ func (cs *CachableSource) Scan() error { return err } txn := iradix.New().Txn() - err = filepath.Walk(string(cs.root), func(path string, info os.FileInfo, err error) error { + err = filepath.Walk(cs.root, func(path string, info os.FileInfo, err error) error { if err != nil { return errors.Wrapf(err, "failed to walk %s", path) } diff --git a/builder/remotecontext/tarsum_test.go b/builder/remotecontext/tarsum_test.go index 8736be76f9..a398839ab3 100644 --- a/builder/remotecontext/tarsum_test.go +++ b/builder/remotecontext/tarsum_test.go @@ -35,7 +35,7 @@ func TestCloseRootDirectory(t *testing.T) { t.Fatalf("Error while executing Close: %s", err) } - _, err = os.Stat(string(src.Root())) + _, err = os.Stat(src.Root()) if !errors.Is(err, os.ErrNotExist) { t.Fatal("Directory should not exist at this point") @@ -118,7 +118,7 @@ func TestRemoveDirectory(t *testing.T) { src := makeTestArchiveContext(t, contextDir) - _, err = os.Stat(filepath.Join(string(src.Root()), relativePath)) + _, err = os.Stat(filepath.Join(src.Root(), relativePath)) if err != nil { t.Fatalf("Statting %s shouldn't fail: %+v", relativePath, err) } @@ -129,7 +129,7 @@ func TestRemoveDirectory(t *testing.T) { t.Fatalf("Error when executing Remove: %s", err) } - _, err = os.Stat(filepath.Join(string(src.Root()), relativePath)) + _, err = os.Stat(filepath.Join(src.Root(), relativePath)) if !errors.Is(err, os.ErrNotExist) { t.Fatalf("Directory should not exist at this point: %+v ", err) } diff --git a/container/archive.go b/container/archive.go index b4c81488ab..c96ea1b868 100644 --- a/container/archive.go +++ b/container/archive.go @@ -64,7 +64,7 @@ func (container *Container) StatPath(resolvedPath, absPath string) (stat *types. return nil, err } - linkTarget, err = filepath.Rel(string(container.BaseFS), hostPath) + linkTarget, err = filepath.Rel(container.BaseFS, hostPath) if err != nil { return nil, err } diff --git a/container/container.go b/container/container.go index b8454a73d4..9c15d1f384 100644 --- a/container/container.go +++ b/container/container.go @@ -304,13 +304,13 @@ func (container *Container) GetResourcePath(path string) (string, error) { } // IMPORTANT - These are paths on the OS where the daemon is running, hence // any filepath operations must be done in an OS agnostic way. - r, e := containerfs.ResolveScopedPath(string(container.BaseFS), containerfs.CleanScopedPath(path)) + r, e := containerfs.ResolveScopedPath(container.BaseFS, containerfs.CleanScopedPath(path)) // Log this here on the daemon side as there's otherwise no indication apart // from the error being propagated all the way back to the client. This makes // debugging significantly easier and clearly indicates the error comes from the daemon. if e != nil { - logrus.Errorf("Failed to ResolveScopedPath BaseFS %s path %s %s\n", string(container.BaseFS), path, e) + logrus.Errorf("Failed to ResolveScopedPath BaseFS %s path %s %s\n", container.BaseFS, path, e) } return r, e } diff --git a/daemon/archive.go b/daemon/archive.go index 504c1f971a..f163174242 100644 --- a/daemon/archive.go +++ b/daemon/archive.go @@ -246,7 +246,7 @@ func (daemon *Daemon) containerArchivePath(container *container.Container, path } opts := archive.TarResourceRebaseOpts(sourceBase, filepath.Base(absPath)) - data, err := archivePath(driver, sourceDir, opts, string(container.BaseFS)) + data, err := archivePath(driver, sourceDir, opts, container.BaseFS) if err != nil { return nil, nil, err } @@ -333,14 +333,14 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path // a volume file path. var baseRel string if strings.HasPrefix(resolvedPath, `\\?\Volume{`) { - if strings.HasPrefix(resolvedPath, string(driver)) { - baseRel = resolvedPath[len(string(driver)):] + if strings.HasPrefix(resolvedPath, driver) { + baseRel = resolvedPath[len(driver):] if baseRel[:1] == `\` { baseRel = baseRel[1:] } } } else { - baseRel, err = filepath.Rel(string(driver), resolvedPath) + baseRel, err = filepath.Rel(driver, resolvedPath) } if err != nil { return err @@ -372,7 +372,7 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path } } - if err := extractArchive(driver, content, resolvedPath, options, string(container.BaseFS)); err != nil { + if err := extractArchive(driver, content, resolvedPath, options, container.BaseFS); err != nil { return err } @@ -434,7 +434,7 @@ func (daemon *Daemon) containerCopy(container *container.Container, resource str archv, err := archivePath(driver, basePath, &archive.TarOptions{ Compression: archive.Uncompressed, IncludeFiles: filter, - }, string(container.BaseFS)) + }, container.BaseFS) if err != nil { return nil, err } diff --git a/daemon/export.go b/daemon/export.go index 1bed03b8f6..a98425cbc9 100644 --- a/daemon/export.go +++ b/daemon/export.go @@ -61,10 +61,10 @@ func (daemon *Daemon) containerExport(container *container.Container) (arch io.R return nil, err } - archv, err := archivePath(basefs, string(basefs), &archive.TarOptions{ + archv, err := archivePath(basefs, basefs, &archive.TarOptions{ Compression: archive.Uncompressed, IDMap: daemon.idMapping, - }, string(basefs)) + }, basefs) if err != nil { rwlayer.Unmount() return nil, err diff --git a/daemon/graphdriver/aufs/aufs.go b/daemon/graphdriver/aufs/aufs.go index 08ab302bb1..8066549a62 100644 --- a/daemon/graphdriver/aufs/aufs.go +++ b/daemon/graphdriver/aufs/aufs.go @@ -370,7 +370,7 @@ func (a *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) { } } if count := a.ctr.Increment(m); count > 1 { - return containerfs.NewLocalContainerFS(m), nil + return m, nil } // If a dir does not have a parent ( no layers )do not try to mount @@ -384,7 +384,7 @@ func (a *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) { a.pathCacheLock.Lock() a.pathCache[id] = m a.pathCacheLock.Unlock() - return containerfs.NewLocalContainerFS(m), nil + return m, nil } // Put unmounts and updates list of active mounts. diff --git a/daemon/graphdriver/aufs/aufs_test.go b/daemon/graphdriver/aufs/aufs_test.go index 05c2ed778d..26142acfc5 100644 --- a/daemon/graphdriver/aufs/aufs_test.go +++ b/daemon/graphdriver/aufs/aufs_test.go @@ -43,14 +43,6 @@ func testInit(dir string, t testing.TB) graphdriver.Driver { return d } -func driverGet(d *Driver, id string, mntLabel string) (string, error) { - mnt, err := d.Get(id, mntLabel) - if err != nil { - return "", err - } - return string(mnt), nil -} - func newDriver(t testing.TB) *Driver { if err := os.MkdirAll(tmp, 0755); err != nil { t.Fatal(err) @@ -180,7 +172,7 @@ func TestGetWithoutParent(t *testing.T) { t.Fatal(err) } expected := path.Join(tmp, "diff", "1") - if string(diffPath) != expected { + if diffPath != expected { t.Fatalf("Expected path %s got %s", expected, diffPath) } } @@ -262,8 +254,8 @@ func TestMountWithParent(t *testing.T) { } expected := path.Join(tmp, "mnt", "2") - if string(mntPath) != expected { - t.Fatalf("Expected %s got %s", expected, string(mntPath)) + if mntPath != expected { + t.Fatalf("Expected %s got %s", expected, mntPath) } } @@ -323,7 +315,7 @@ func TestGetDiff(t *testing.T) { t.Fatal(err) } - diffPath, err := driverGet(d, "1", "") + diffPath, err := d.Get("1", "") if err != nil { t.Fatal(err) } @@ -367,7 +359,7 @@ func TestChanges(t *testing.T) { } }() - mntPoint, err := driverGet(d, "2", "") + mntPoint, err := d.Get("2", "") if err != nil { t.Fatal(err) } @@ -406,7 +398,7 @@ func TestChanges(t *testing.T) { if err := d.CreateReadWrite("3", "2", nil); err != nil { t.Fatal(err) } - mntPoint, err = driverGet(d, "3", "") + mntPoint, err = d.Get("3", "") if err != nil { t.Fatal(err) } @@ -452,7 +444,7 @@ func TestDiffSize(t *testing.T) { t.Fatal(err) } - diffPath, err := driverGet(d, "1", "") + diffPath, err := d.Get("1", "") if err != nil { t.Fatal(err) } @@ -494,7 +486,7 @@ func TestChildDiffSize(t *testing.T) { t.Fatal(err) } - diffPath, err := driverGet(d, "1", "") + diffPath, err := d.Get("1", "") if err != nil { t.Fatal(err) } @@ -595,7 +587,7 @@ func TestApplyDiff(t *testing.T) { t.Fatal(err) } - diffPath, err := driverGet(d, "1", "") + diffPath, err := d.Get("1", "") if err != nil { t.Fatal(err) } @@ -630,7 +622,7 @@ func TestApplyDiff(t *testing.T) { // Ensure that the file is in the mount point for id 3 - mountPoint, err := driverGet(d, "3", "") + mountPoint, err := d.Get("3", "") if err != nil { t.Fatal(err) } @@ -673,7 +665,7 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) { err := d.CreateReadWrite(current, parent, nil) assert.NilError(t, err, "current layer %d", i) - point, err := driverGet(d, current, "") + point, err := d.Get(current, "") assert.NilError(t, err, "current layer %d", i) f, err := os.Create(path.Join(point, current)) @@ -689,7 +681,7 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) { } // Perform the actual mount for the top most image - point, err := driverGet(d, last, "") + point, err := d.Get(last, "") assert.NilError(t, err) files, err := os.ReadDir(point) assert.NilError(t, err) diff --git a/daemon/graphdriver/btrfs/btrfs.go b/daemon/graphdriver/btrfs/btrfs.go index f0bf1ab54d..8373d921a5 100644 --- a/daemon/graphdriver/btrfs/btrfs.go +++ b/daemon/graphdriver/btrfs/btrfs.go @@ -649,7 +649,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) { } } - return containerfs.NewLocalContainerFS(dir), nil + return dir, nil } // Put is not implemented for BTRFS as there is no cleanup required for the id. diff --git a/daemon/graphdriver/btrfs/btrfs_test.go b/daemon/graphdriver/btrfs/btrfs_test.go index 05d0f48e9c..511f29af7d 100644 --- a/daemon/graphdriver/btrfs/btrfs_test.go +++ b/daemon/graphdriver/btrfs/btrfs_test.go @@ -36,14 +36,12 @@ func TestBtrfsSubvolDelete(t *testing.T) { } defer graphtest.PutDriver(t) - dirFS, err := d.Get("test", "") + dir, err := d.Get("test", "") if err != nil { t.Fatal(err) } defer d.Put("test") - dir := string(dirFS) - if err := subvolCreate(dir, "subvoltest"); err != nil { t.Fatal(err) } diff --git a/daemon/graphdriver/devmapper/driver.go b/daemon/graphdriver/devmapper/driver.go index ec8c20d513..894345e468 100644 --- a/daemon/graphdriver/devmapper/driver.go +++ b/daemon/graphdriver/devmapper/driver.go @@ -181,7 +181,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) { mp := path.Join(d.home, "mnt", id) rootFs := path.Join(mp, "rootfs") if count := d.ctr.Increment(mp); count > 1 { - return containerfs.NewLocalContainerFS(rootFs), nil + return rootFs, nil } root := d.idMap.RootPair() @@ -219,7 +219,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) { } } - return containerfs.NewLocalContainerFS(rootFs), nil + return rootFs, nil } // Put unmounts a device and removes it. diff --git a/daemon/graphdriver/fsdiff.go b/daemon/graphdriver/fsdiff.go index 331d60d392..2a201dc2f5 100644 --- a/daemon/graphdriver/fsdiff.go +++ b/daemon/graphdriver/fsdiff.go @@ -50,7 +50,7 @@ func (gdw *NaiveDiffDriver) Diff(id, parent string) (arch io.ReadCloser, err err if err != nil { return nil, err } - layerFs := string(layerRootFs) + layerFs := layerRootFs defer func() { if err != nil { @@ -70,14 +70,12 @@ func (gdw *NaiveDiffDriver) Diff(id, parent string) (arch io.ReadCloser, err err }), nil } - parentRootFs, err := driver.Get(parent, "") + parentFs, err := driver.Get(parent, "") if err != nil { return nil, err } defer driver.Put(parent) - parentFs := string(parentRootFs) - changes, err := archive.ChangesDirs(layerFs, parentFs) if err != nil { return nil, err @@ -106,22 +104,20 @@ func (gdw *NaiveDiffDriver) Diff(id, parent string) (arch io.ReadCloser, err err func (gdw *NaiveDiffDriver) Changes(id, parent string) ([]archive.Change, error) { driver := gdw.ProtoDriver - layerRootFs, err := driver.Get(id, "") + layerFs, err := driver.Get(id, "") if err != nil { return nil, err } defer driver.Put(id) - layerFs := string(layerRootFs) parentFs := "" if parent != "" { - parentRootFs, err := driver.Get(parent, "") + parentFs, err = driver.Get(parent, "") if err != nil { return nil, err } defer driver.Put(parent) - parentFs = string(parentRootFs) } return archive.ChangesDirs(layerFs, parentFs) @@ -140,7 +136,7 @@ func (gdw *NaiveDiffDriver) ApplyDiff(id, parent string, diff io.Reader) (size i } defer driver.Put(id) - layerFs := string(layerRootFs) + layerFs := layerRootFs options := &archive.TarOptions{IDMap: gdw.idMap} start := time.Now().UTC() logrus.WithField("id", id).Debug("Start untar layer") @@ -169,5 +165,5 @@ func (gdw *NaiveDiffDriver) DiffSize(id, parent string) (size int64, err error) } defer driver.Put(id) - return archive.ChangesSize(string(layerFs), changes), nil + return archive.ChangesSize(layerFs, changes), nil } diff --git a/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go b/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go index a39d58d327..aa7799e1c9 100644 --- a/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go +++ b/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go @@ -316,14 +316,14 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e if err != nil { // If no lower, just return diff directory if os.IsNotExist(err) { - return containerfs.NewLocalContainerFS(diffDir), nil + return diffDir, nil } return "", err } mergedDir := path.Join(dir, mergedDirName) if count := d.ctr.Increment(mergedDir); count > 1 { - return containerfs.NewLocalContainerFS(mergedDir), nil + return mergedDir, nil } defer func() { if retErr != nil { @@ -380,7 +380,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e return "", errors.Wrapf(err, "using mount program %s: %s", binary, output) } - return containerfs.NewLocalContainerFS(mergedDir), nil + return mergedDir, nil } // Put unmounts the mount path created for the give id. diff --git a/daemon/graphdriver/graphtest/graphbench_unix.go b/daemon/graphdriver/graphtest/graphbench_unix.go index 88ca80005a..422c3ec23d 100644 --- a/daemon/graphdriver/graphtest/graphbench_unix.go +++ b/daemon/graphdriver/graphtest/graphbench_unix.go @@ -250,7 +250,7 @@ func DriverBenchDeepLayerRead(b *testing.B, layerCount int, drivername string, d for i := 0; i < b.N; i++ { // Read content - c, err := os.ReadFile(filepath.Join(string(root), "testfile.txt")) + c, err := os.ReadFile(filepath.Join(root, "testfile.txt")) if err != nil { b.Fatal(err) } diff --git a/daemon/graphdriver/graphtest/graphtest_unix.go b/daemon/graphdriver/graphtest/graphtest_unix.go index f8fa88dcc6..b0b93d281d 100644 --- a/daemon/graphdriver/graphtest/graphtest_unix.go +++ b/daemon/graphdriver/graphtest/graphtest_unix.go @@ -96,10 +96,10 @@ func DriverTestCreateEmpty(t testing.TB, drivername string, driverOptions ...str dir, err := driver.Get("empty", "") assert.NilError(t, err) - verifyFile(t, string(dir), 0755|os.ModeDir, 0, 0) + verifyFile(t, dir, 0755|os.ModeDir, 0, 0) // Verify that the directory is empty - fis, err := readDir(string(dir)) + fis, err := readDir(dir) assert.NilError(t, err) assert.Check(t, is.Len(fis, 0)) @@ -324,19 +324,19 @@ func DriverTestSetQuota(t *testing.T, drivername string, required bool) { quota := uint64(50 * units.MiB) // Try to write a file smaller than quota, and ensure it works - err = writeRandomFile(path.Join(string(mountPath), "smallfile"), quota/2) + err = writeRandomFile(path.Join(mountPath, "smallfile"), quota/2) if err != nil { t.Fatal(err) } - defer os.Remove(path.Join(string(mountPath), "smallfile")) + defer os.Remove(path.Join(mountPath, "smallfile")) // Try to write a file bigger than quota. We've already filled up half the quota, so hitting the limit should be easy - err = writeRandomFile(path.Join(string(mountPath), "bigfile"), quota) + err = writeRandomFile(path.Join(mountPath, "bigfile"), quota) if err == nil { t.Fatalf("expected write to fail(), instead had success") } if pathError, ok := err.(*os.PathError); ok && pathError.Err != unix.EDQUOT && pathError.Err != unix.ENOSPC { - os.Remove(path.Join(string(mountPath), "bigfile")) + os.Remove(path.Join(mountPath, "bigfile")) t.Fatalf("expect write() to fail with %v or %v, got %v", unix.EDQUOT, unix.ENOSPC, pathError.Err) } } diff --git a/daemon/graphdriver/graphtest/testutil.go b/daemon/graphdriver/graphtest/testutil.go index 6f02c5645b..20a0da8b31 100644 --- a/daemon/graphdriver/graphtest/testutil.go +++ b/daemon/graphdriver/graphtest/testutil.go @@ -36,17 +36,17 @@ func addFiles(drv graphdriver.Driver, layer string, seed int64) error { } defer drv.Put(layer) - if err := os.WriteFile(filepath.Join(string(root), "file-a"), randomContent(64, seed), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root, "file-a"), randomContent(64, seed), 0755); err != nil { return err } - if err := os.MkdirAll(filepath.Join(string(root), "dir-b"), 0755); err != nil { + if err := os.MkdirAll(filepath.Join(root, "dir-b"), 0755); err != nil { return err } - if err := os.WriteFile(filepath.Join(string(root), "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root, "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil { return err } - return os.WriteFile(filepath.Join(string(root), "file-c"), randomContent(128*128, seed+2), 0755) + return os.WriteFile(filepath.Join(root, "file-c"), randomContent(128*128, seed+2), 0755) } func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) error { @@ -56,7 +56,7 @@ func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) e } defer drv.Put(layer) - fileContent, err := os.ReadFile(filepath.Join(string(root), filename)) + fileContent, err := os.ReadFile(filepath.Join(root, filename)) if err != nil { return err } @@ -75,7 +75,7 @@ func addFile(drv graphdriver.Driver, layer, filename string, content []byte) err } defer drv.Put(layer) - return os.WriteFile(filepath.Join(string(root), filename), content, 0755) + return os.WriteFile(filepath.Join(root, filename), content, 0755) } func addDirectory(drv graphdriver.Driver, layer, dir string) error { @@ -85,7 +85,7 @@ func addDirectory(drv graphdriver.Driver, layer, dir string) error { } defer drv.Put(layer) - return os.MkdirAll(filepath.Join(string(root), dir), 0755) + return os.MkdirAll(filepath.Join(root, dir), 0755) } func removeAll(drv graphdriver.Driver, layer string, names ...string) error { @@ -96,7 +96,7 @@ func removeAll(drv graphdriver.Driver, layer string, names ...string) error { defer drv.Put(layer) for _, filename := range names { - if err := os.RemoveAll(filepath.Join(string(root), filename)); err != nil { + if err := os.RemoveAll(filepath.Join(root, filename)); err != nil { return err } } @@ -110,8 +110,8 @@ func checkFileRemoved(drv graphdriver.Driver, layer, filename string) error { } defer drv.Put(layer) - if _, err := os.Stat(filepath.Join(string(root), filename)); err == nil { - return fmt.Errorf("file still exists: %s", filepath.Join(string(root), filename)) + if _, err := os.Stat(filepath.Join(root, filename)); err == nil { + return fmt.Errorf("file still exists: %s", filepath.Join(root, filename)) } else if !os.IsNotExist(err) { return err } @@ -127,7 +127,7 @@ func addManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) e defer drv.Put(layer) for i := 0; i < count; i += 100 { - dir := filepath.Join(string(root), fmt.Sprintf("directory-%d", i)) + dir := filepath.Join(root, fmt.Sprintf("directory-%d", i)) if err := os.MkdirAll(dir, 0755); err != nil { return err } @@ -152,7 +152,7 @@ func changeManyFiles(drv graphdriver.Driver, layer string, count int, seed int64 var changes []archive.Change for i := 0; i < count; i += 100 { archiveRoot := fmt.Sprintf("/directory-%d", i) - if err := os.MkdirAll(filepath.Join(string(root), archiveRoot), 0755); err != nil { + if err := os.MkdirAll(filepath.Join(root, archiveRoot), 0755); err != nil { return nil, err } for j := 0; i+j < count && j < 100; j++ { @@ -168,21 +168,21 @@ func changeManyFiles(drv graphdriver.Driver, layer string, count int, seed int64 case 0: change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j)) change.Kind = archive.ChangeModify - if err := os.WriteFile(filepath.Join(string(root), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root, change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil { return nil, err } // Add file case 1: change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d-%d", seed, i+j)) change.Kind = archive.ChangeAdd - if err := os.WriteFile(filepath.Join(string(root), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root, change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil { return nil, err } // Remove file case 2: change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j)) change.Kind = archive.ChangeDelete - if err := os.Remove(filepath.Join(string(root), change.Path)); err != nil { + if err := os.Remove(filepath.Join(root, change.Path)); err != nil { return nil, err } } @@ -201,7 +201,7 @@ func checkManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) defer drv.Put(layer) for i := 0; i < count; i += 100 { - dir := filepath.Join(string(root), fmt.Sprintf("directory-%d", i)) + dir := filepath.Join(root, fmt.Sprintf("directory-%d", i)) for j := 0; i+j < count && j < 100; j++ { file := filepath.Join(dir, fmt.Sprintf("file-%d", i+j)) fileContent, err := os.ReadFile(file) @@ -254,10 +254,10 @@ func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error { } defer drv.Put(layer) - if err := os.WriteFile(filepath.Join(string(root), "top-id"), []byte(layer), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root, "top-id"), []byte(layer), 0755); err != nil { return err } - layerDir := filepath.Join(string(root), fmt.Sprintf("layer-%d", i)) + layerDir := filepath.Join(root, fmt.Sprintf("layer-%d", i)) if err := os.MkdirAll(layerDir, 0755); err != nil { return err } @@ -291,7 +291,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error { } defer drv.Put(layer) - layerIDBytes, err := os.ReadFile(filepath.Join(string(root), "top-id")) + layerIDBytes, err := os.ReadFile(filepath.Join(root, "top-id")) if err != nil { return err } @@ -301,7 +301,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error { } for i := count; i > 0; i-- { - layerDir := filepath.Join(string(root), fmt.Sprintf("layer-%d", i)) + layerDir := filepath.Join(root, fmt.Sprintf("layer-%d", i)) thisLayerIDBytes, err := os.ReadFile(filepath.Join(layerDir, "layer-id")) if err != nil { diff --git a/daemon/graphdriver/graphtest/testutil_unix.go b/daemon/graphdriver/graphtest/testutil_unix.go index e8b0f8786f..d42682203e 100644 --- a/daemon/graphdriver/graphtest/testutil_unix.go +++ b/daemon/graphdriver/graphtest/testutil_unix.go @@ -45,11 +45,11 @@ func createBase(t testing.TB, driver graphdriver.Driver, name string) { assert.NilError(t, err) defer driver.Put(name) - subdir := filepath.Join(string(dirFS), "a subdir") + subdir := filepath.Join(dirFS, "a subdir") assert.NilError(t, os.Mkdir(subdir, 0705|os.ModeSticky)) assert.NilError(t, contdriver.LocalDriver.Lchown(subdir, 1, 2)) - file := filepath.Join(string(dirFS), "a file") + file := filepath.Join(dirFS, "a file") err = os.WriteFile(file, []byte("Some data"), 0222|os.ModeSetuid) assert.NilError(t, err) } @@ -59,13 +59,13 @@ func verifyBase(t testing.TB, driver graphdriver.Driver, name string) { assert.NilError(t, err) defer driver.Put(name) - subdir := filepath.Join(string(dirFS), "a subdir") + subdir := filepath.Join(dirFS, "a subdir") verifyFile(t, subdir, 0705|os.ModeDir|os.ModeSticky, 1, 2) - file := filepath.Join(string(dirFS), "a file") + file := filepath.Join(dirFS, "a file") verifyFile(t, file, 0222|os.ModeSetuid, 0, 0) - files, err := readDir(string(dirFS)) + files, err := readDir(dirFS) assert.NilError(t, err) assert.Check(t, is.Len(files, 2)) } diff --git a/daemon/graphdriver/overlay/overlay.go b/daemon/graphdriver/overlay/overlay.go index 9c23dc0c15..01d4982e12 100644 --- a/daemon/graphdriver/overlay/overlay.go +++ b/daemon/graphdriver/overlay/overlay.go @@ -349,12 +349,12 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, err erro // If id has a root, just return it rootDir := path.Join(dir, "root") if _, err := os.Stat(rootDir); err == nil { - return containerfs.NewLocalContainerFS(rootDir), nil + return rootDir, nil } mergedDir := path.Join(dir, "merged") if count := d.ctr.Increment(mergedDir); count > 1 { - return containerfs.NewLocalContainerFS(mergedDir), nil + return mergedDir, nil } defer func() { if err != nil { @@ -391,7 +391,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, err erro if err := root.Chown(path.Join(workDir, "work")); err != nil { return "", err } - return containerfs.NewLocalContainerFS(mergedDir), nil + return mergedDir, nil } // Put unmounts the mount path created for the give id. diff --git a/daemon/graphdriver/overlay2/overlay.go b/daemon/graphdriver/overlay2/overlay.go index b4b807e796..9140ea089f 100644 --- a/daemon/graphdriver/overlay2/overlay.go +++ b/daemon/graphdriver/overlay2/overlay.go @@ -526,14 +526,14 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e if err != nil { // If no lower, just return diff directory if os.IsNotExist(err) { - return containerfs.NewLocalContainerFS(diffDir), nil + return diffDir, nil } return "", err } mergedDir := path.Join(dir, mergedDirName) if count := d.ctr.Increment(mergedDir); count > 1 { - return containerfs.NewLocalContainerFS(mergedDir), nil + return mergedDir, nil } defer func() { if retErr != nil { @@ -613,7 +613,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e } } - return containerfs.NewLocalContainerFS(mergedDir), nil + return mergedDir, nil } // Put unmounts the mount path created for the give id. diff --git a/daemon/graphdriver/proxy.go b/daemon/graphdriver/proxy.go index 17abfca6d4..94185131d0 100644 --- a/daemon/graphdriver/proxy.go +++ b/daemon/graphdriver/proxy.go @@ -141,7 +141,7 @@ func (d *graphDriverProxy) Get(id, mountLabel string) (containerfs.ContainerFS, if ret.Err != "" { err = errors.New(ret.Err) } - return containerfs.NewLocalContainerFS(d.p.ScopedPath(ret.Dir)), err + return d.p.ScopedPath(ret.Dir), err } func (d *graphDriverProxy) Put(id string) error { diff --git a/daemon/graphdriver/vfs/driver.go b/daemon/graphdriver/vfs/driver.go index 92e2f115ec..d99b82e833 100644 --- a/daemon/graphdriver/vfs/driver.go +++ b/daemon/graphdriver/vfs/driver.go @@ -172,7 +172,7 @@ func (d *Driver) create(id, parent string, size uint64) error { if err != nil { return fmt.Errorf("%s: %s", parent, err) } - return CopyDir(string(parentDir), dir) + return CopyDir(parentDir, dir) } func (d *Driver) dir(id string) string { @@ -192,7 +192,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) { } else if !st.IsDir() { return "", fmt.Errorf("%s: not a directory", dir) } - return containerfs.NewLocalContainerFS(dir), nil + return dir, nil } // Put is a noop for vfs that return nil for the error, since this driver has no runtime resources to clean up. diff --git a/daemon/graphdriver/windows/windows.go b/daemon/graphdriver/windows/windows.go index 4c89cfe97e..383c3b7473 100644 --- a/daemon/graphdriver/windows/windows.go +++ b/daemon/graphdriver/windows/windows.go @@ -402,7 +402,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) { return "", err } if count := d.ctr.Increment(rID); count > 1 { - return containerfs.NewLocalContainerFS(d.cache[rID]), nil + return d.cache[rID], nil } // Getting the layer paths must be done outside of the lock. @@ -447,7 +447,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) { dir = d.dir(id) } - return containerfs.NewLocalContainerFS(dir), nil + return dir, nil } // Put adds a new layer to the driver. @@ -651,7 +651,7 @@ func (d *Driver) DiffSize(id, parent string) (size int64, err error) { } defer d.Put(id) - return archive.ChangesSize(string(layerFs), changes), nil + return archive.ChangesSize(layerFs, changes), nil } // GetMetadata returns custom driver information. diff --git a/daemon/graphdriver/zfs/zfs.go b/daemon/graphdriver/zfs/zfs.go index aca35e0abd..82f72bf698 100644 --- a/daemon/graphdriver/zfs/zfs.go +++ b/daemon/graphdriver/zfs/zfs.go @@ -368,7 +368,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e defer d.locker.Unlock(id) mountpoint := d.mountPath(id) if count := d.ctr.Increment(mountpoint); count > 1 { - return containerfs.NewLocalContainerFS(mountpoint), nil + return mountpoint, nil } defer func() { if retErr != nil { @@ -404,7 +404,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e return "", fmt.Errorf("error modifying zfs mountpoint (%s) directory ownership: %v", mountpoint, err) } - return containerfs.NewLocalContainerFS(mountpoint), nil + return mountpoint, nil } // Put removes the existing mountpoint for the given id if it exists. diff --git a/daemon/initlayer/setup_unix.go b/daemon/initlayer/setup_unix.go index 07905f9463..132e105d5c 100644 --- a/daemon/initlayer/setup_unix.go +++ b/daemon/initlayer/setup_unix.go @@ -20,7 +20,7 @@ import ( // the container from unwanted side-effects on the rw layer. func Setup(initLayerFs containerfs.ContainerFS, rootIdentity idtools.Identity) error { // Since all paths are local to the container, we can just extract initLayerFs.Path() - initLayer := string(initLayerFs) + initLayer := initLayerFs for pth, typ := range map[string]string{ "/dev/pts": "dir", diff --git a/daemon/list_windows.go b/daemon/list_windows.go index 7c7b5fa856..62daa36fc8 100644 --- a/daemon/list_windows.go +++ b/daemon/list_windows.go @@ -9,7 +9,7 @@ import ( // excludeByIsolation is a platform specific helper function to support PS // filtering by Isolation. This is a Windows-only concept, so is a no-op on Unix. func excludeByIsolation(container *container.Snapshot, ctx *listContext) iterationAction { - i := strings.ToLower(string(container.HostConfig.Isolation)) + i := strings.ToLower(container.HostConfig.Isolation) if i == "" { i = "default" } diff --git a/daemon/oci_linux.go b/daemon/oci_linux.go index 71a04d6b84..b0ca314fd8 100644 --- a/daemon/oci_linux.go +++ b/daemon/oci_linux.go @@ -730,7 +730,7 @@ func WithCommonOptions(daemon *Daemon, c *container.Container) coci.SpecOpts { } if !daemon.UsesSnapshotter() { s.Root = &specs.Root{ - Path: string(c.BaseFS), + Path: c.BaseFS, Readonly: c.HostConfig.ReadonlyRootfs, } } diff --git a/daemon/oci_linux_test.go b/daemon/oci_linux_test.go index 42084c900d..d7a68b88bf 100644 --- a/daemon/oci_linux_test.go +++ b/daemon/oci_linux_test.go @@ -10,7 +10,6 @@ import ( "github.com/docker/docker/daemon/config" "github.com/docker/docker/daemon/network" "github.com/docker/docker/libnetwork" - "github.com/docker/docker/pkg/containerfs" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/skip" @@ -36,7 +35,7 @@ func setupFakeDaemon(t *testing.T, c *container.Container) *Daemon { } c.Root = root - c.BaseFS = containerfs.NewLocalContainerFS(rootfs) + c.BaseFS = rootfs if c.Config == nil { c.Config = new(containertypes.Config) diff --git a/daemon/oci_windows.go b/daemon/oci_windows.go index 0db8135415..e2205b8ca2 100644 --- a/daemon/oci_windows.go +++ b/daemon/oci_windows.go @@ -240,7 +240,7 @@ func (daemon *Daemon) createSpecWindowsFields(c *container.Container, s *specs.S return errors.New("createSpecWindowsFields: BaseFS of container " + c.ID + " is unexpectedly empty") } - s.Root.Path = string(c.BaseFS) // This is not set for Hyper-V containers + s.Root.Path = c.BaseFS // This is not set for Hyper-V containers if !strings.HasSuffix(s.Root.Path, `\`) { s.Root.Path = s.Root.Path + `\` // Ensure a correctly formatted volume GUID path \\?\Volume{GUID}\ } diff --git a/integration/plugin/graphdriver/external_test.go b/integration/plugin/graphdriver/external_test.go index c5a08cd89e..f96a7dcc32 100644 --- a/integration/plugin/graphdriver/external_test.go +++ b/integration/plugin/graphdriver/external_test.go @@ -219,7 +219,7 @@ func setupPlugin(t *testing.T, ec map[string]*graphEventsCounter, ext string, mu respond(w, err) return } - respond(w, &graphDriverResponse{Dir: string(dir)}) + respond(w, &graphDriverResponse{Dir: dir}) }) mux.HandleFunc("/GraphDriver.Put", func(w http.ResponseWriter, r *http.Request) { diff --git a/layer/layer_store.go b/layer/layer_store.go index ae8ffe8d72..623d494012 100644 --- a/layer/layer_store.go +++ b/layer/layer_store.go @@ -786,5 +786,5 @@ func (n *naiveDiffPathDriver) DiffGetter(id string) (graphdriver.FileGetCloser, if err != nil { return nil, err } - return &fileGetPutter{storage.NewPathFileGetter(string(p)), n.Driver, id}, nil + return &fileGetPutter{storage.NewPathFileGetter(p), n.Driver, id}, nil } diff --git a/layer/layer_test.go b/layer/layer_test.go index 65ea762a6e..fe9b36a0dc 100644 --- a/layer/layer_test.go +++ b/layer/layer_test.go @@ -139,7 +139,7 @@ func newTestFile(name string, content []byte, perm os.FileMode) FileApplier { } func (tf *testFile) ApplyFile(root containerfs.ContainerFS) error { - fullPath := filepath.Join(string(root), tf.name) + fullPath := filepath.Join(root, tf.name) if err := os.MkdirAll(filepath.Dir(fullPath), 0755); err != nil { return err } @@ -267,7 +267,7 @@ func TestMountAndRegister(t *testing.T) { t.Fatal(err) } - b, err := os.ReadFile(filepath.Join(string(path2), "testfile.txt")) + b, err := os.ReadFile(filepath.Join(path2, "testfile.txt")) if err != nil { t.Fatal(err) } @@ -375,7 +375,7 @@ func TestStoreRestore(t *testing.T) { t.Fatal(err) } - if err := os.WriteFile(filepath.Join(string(pathFS), "testfile.txt"), []byte("nothing here"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(pathFS, "testfile.txt"), []byte("nothing here"), 0644); err != nil { t.Fatal(err) } @@ -409,20 +409,20 @@ func TestStoreRestore(t *testing.T) { if mountPath, err := m2.Mount(""); err != nil { t.Fatal(err) - } else if string(pathFS) != string(mountPath) { - t.Fatalf("Unexpected path %s, expected %s", string(mountPath), string(pathFS)) + } else if pathFS != mountPath { + t.Fatalf("Unexpected path %s, expected %s", mountPath, pathFS) } if mountPath, err := m2.Mount(""); err != nil { t.Fatal(err) - } else if string(pathFS) != string(mountPath) { - t.Fatalf("Unexpected path %s, expected %s", string(mountPath), string(pathFS)) + } else if pathFS != mountPath { + t.Fatalf("Unexpected path %s, expected %s", mountPath, pathFS) } if err := m2.Unmount(); err != nil { t.Fatal(err) } - b, err := os.ReadFile(filepath.Join(string(pathFS), "testfile.txt")) + b, err := os.ReadFile(filepath.Join(pathFS, "testfile.txt")) if err != nil { t.Fatal(err) } @@ -597,7 +597,7 @@ func tarFromFiles(files ...FileApplier) ([]byte, error) { defer os.RemoveAll(td) for _, f := range files { - if err := f.ApplyFile(containerfs.NewLocalContainerFS(td)); err != nil { + if err := f.ApplyFile(td); err != nil { return nil, err } } diff --git a/layer/layer_windows.go b/layer/layer_windows.go index b6a51840ed..350a671124 100644 --- a/layer/layer_windows.go +++ b/layer/layer_windows.go @@ -37,7 +37,7 @@ func GetLayerPath(s Store, layer ChainID) (string, error) { return "", err } - return string(path), nil + return path, nil } func (ls *layerStore) mountID(name string) string { diff --git a/layer/mount_test.go b/layer/mount_test.go index 6c7d5d4997..1245ee2dfc 100644 --- a/layer/mount_test.go +++ b/layer/mount_test.go @@ -47,12 +47,12 @@ func TestMountInit(t *testing.T) { t.Fatal(err) } - fi, err := os.Stat(filepath.Join(string(pathFS), "testfile.txt")) + fi, err := os.Stat(filepath.Join(pathFS, "testfile.txt")) if err != nil { t.Fatal(err) } - f, err := os.Open(filepath.Join(string(pathFS), "testfile.txt")) + f, err := os.Open(filepath.Join(pathFS, "testfile.txt")) if err != nil { t.Fatal(err) } @@ -107,7 +107,7 @@ func TestMountSize(t *testing.T) { t.Fatal(err) } - if err := os.WriteFile(filepath.Join(string(pathFS), "file2"), content2, 0755); err != nil { + if err := os.WriteFile(filepath.Join(pathFS, "file2"), content2, 0755); err != nil { t.Fatal(err) } @@ -159,23 +159,23 @@ func TestMountChanges(t *testing.T) { t.Fatal(err) } - if err := driver.LocalDriver.Lchmod(filepath.Join(string(pathFS), "testfile1.txt"), 0755); err != nil { + if err := driver.LocalDriver.Lchmod(filepath.Join(pathFS, "testfile1.txt"), 0755); err != nil { t.Fatal(err) } - if err := os.WriteFile(filepath.Join(string(pathFS), "testfile1.txt"), []byte("mount data!"), 0755); err != nil { + if err := os.WriteFile(filepath.Join(pathFS, "testfile1.txt"), []byte("mount data!"), 0755); err != nil { t.Fatal(err) } - if err := os.Remove(filepath.Join(string(pathFS), "testfile2.txt")); err != nil { + if err := os.Remove(filepath.Join(pathFS, "testfile2.txt")); err != nil { t.Fatal(err) } - if err := driver.LocalDriver.Lchmod(filepath.Join(string(pathFS), "testfile3.txt"), 0755); err != nil { + if err := driver.LocalDriver.Lchmod(filepath.Join(pathFS, "testfile3.txt"), 0755); err != nil { t.Fatal(err) } - if err := os.WriteFile(filepath.Join(string(pathFS), "testfile4.txt"), []byte("mount data!"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(pathFS, "testfile4.txt"), []byte("mount data!"), 0644); err != nil { t.Fatal(err) } @@ -250,7 +250,7 @@ func TestMountApply(t *testing.T) { t.Fatal(err) } - f, err := os.Open(filepath.Join(string(pathFS), "newfile.txt")) + f, err := os.Open(filepath.Join(pathFS, "newfile.txt")) if err != nil { t.Fatal(err) } diff --git a/libnetwork/ipam/structures.go b/libnetwork/ipam/structures.go index de4130f83d..dd5edf13e1 100644 --- a/libnetwork/ipam/structures.go +++ b/libnetwork/ipam/structures.go @@ -186,7 +186,7 @@ func (aSpace *addrSpace) UnmarshalJSON(data []byte) error { aSpace.scope = datastore.LocalScope s := m["Scope"].(string) - if s == string(datastore.GlobalScope) { + if s == datastore.GlobalScope { aSpace.scope = datastore.GlobalScope } diff --git a/pkg/containerfs/containerfs.go b/pkg/containerfs/containerfs.go index d61bd7ae35..1d600d68d7 100644 --- a/pkg/containerfs/containerfs.go +++ b/pkg/containerfs/containerfs.go @@ -7,13 +7,7 @@ import ( ) // ContainerFS is that represents a root file system -type ContainerFS string - -// NewLocalContainerFS is a helper function to implement daemon's Mount interface -// when the graphdriver mount point is a local path on the machine. -func NewLocalContainerFS(path string) ContainerFS { - return ContainerFS(path) -} +type ContainerFS = string // ResolveScopedPath evaluates the given path scoped to the root. // For example, if root=/a, and path=/b/c, then this function would return /a/b/c. diff --git a/plugin/manager_linux.go b/plugin/manager_linux.go index 7daaf6af40..0bd7f18c39 100644 --- a/plugin/manager_linux.go +++ b/plugin/manager_linux.go @@ -12,7 +12,6 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/daemon/initlayer" "github.com/docker/docker/errdefs" - "github.com/docker/docker/pkg/containerfs" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/plugins" "github.com/docker/docker/pkg/stringid" @@ -55,7 +54,7 @@ func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error { } } - rootFS := containerfs.NewLocalContainerFS(filepath.Join(pm.config.Root, p.PluginObj.ID, rootFSFileName)) + rootFS := filepath.Join(pm.config.Root, p.PluginObj.ID, rootFSFileName) if err := initlayer.Setup(rootFS, idtools.Identity{UID: 0, GID: 0}); err != nil { return errors.WithStack(err) }