diff --git a/builder/remotecontext/archive.go b/builder/remotecontext/archive.go index 7c4a166f40..fa6dd66794 100644 --- a/builder/remotecontext/archive.go +++ b/builder/remotecontext/archive.go @@ -20,7 +20,7 @@ type archiveContext struct { } func (c *archiveContext) Close() error { - return c.root.RemoveAll(c.root.Path()) + return os.RemoveAll(c.root.Path()) } func convertPathError(err error, cleanpath string) error { @@ -91,7 +91,7 @@ func (c *archiveContext) Remove(path string) error { if err != nil { return err } - return c.root.RemoveAll(fullpath) + return os.RemoveAll(fullpath) } func (c *archiveContext) Hash(path string) (string, error) { diff --git a/builder/remotecontext/detect.go b/builder/remotecontext/detect.go index aa4a958dd6..16a405a1f7 100644 --- a/builder/remotecontext/detect.go +++ b/builder/remotecontext/detect.go @@ -162,7 +162,7 @@ func openAt(remote builder.Source, path string) (driver.File, error) { if err != nil { return nil, err } - return remote.Root().Open(fullPath) + return os.Open(fullPath) } // StatAt is a helper for calling Stat on a path from a source @@ -171,7 +171,7 @@ func StatAt(remote builder.Source, path string) (os.FileInfo, error) { if err != nil { return nil, err } - return remote.Root().Stat(fullPath) + return os.Stat(fullPath) } // FullPath is a helper for getting a full path for a path from a source diff --git a/builder/remotecontext/detect_test.go b/builder/remotecontext/detect_test.go index 1b581cdd1a..39a3eefc7e 100644 --- a/builder/remotecontext/detect_test.go +++ b/builder/remotecontext/detect_test.go @@ -119,5 +119,5 @@ func (r *stubRemote) Close() error { return errors.New("not implemented") } func (r *stubRemote) Remove(p string) error { - return r.root.Remove(filepath.Join(r.root.Path(), p)) + return os.Remove(filepath.Join(r.root.Path(), p)) } diff --git a/builder/remotecontext/lazycontext.go b/builder/remotecontext/lazycontext.go index 2b934123ae..6e3155678c 100644 --- a/builder/remotecontext/lazycontext.go +++ b/builder/remotecontext/lazycontext.go @@ -47,7 +47,7 @@ func (c *lazySource) Hash(path string) (string, error) { return "", errors.WithStack(convertPathError(err, cleanPath)) } - fi, err := c.root.Lstat(fullPath) + fi, err := os.Lstat(fullPath) if err != nil { // Backwards compatibility: a missing file returns a path as hash. // This is reached in the case of a broken symlink. @@ -72,7 +72,7 @@ func (c *lazySource) prepareHash(relPath string, fi os.FileInfo) (string, error) return "", errors.Wrapf(err, "failed to create hash for %s", relPath) } if fi.Mode().IsRegular() && fi.Size() > 0 { - f, err := c.root.Open(p) + f, err := os.Open(p) if err != nil { return "", errors.Wrapf(err, "failed to open %s", relPath) } diff --git a/builder/remotecontext/tarsum_test.go b/builder/remotecontext/tarsum_test.go index 273da9f561..9b09feb4dd 100644 --- a/builder/remotecontext/tarsum_test.go +++ b/builder/remotecontext/tarsum_test.go @@ -118,7 +118,7 @@ func TestRemoveDirectory(t *testing.T) { src := makeTestArchiveContext(t, contextDir) - _, err = src.Root().Stat(filepath.Join(src.Root().Path(), relativePath)) + _, err = os.Stat(filepath.Join(src.Root().Path(), 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 = src.Root().Stat(filepath.Join(src.Root().Path(), relativePath)) + _, err = os.Stat(filepath.Join(src.Root().Path(), 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 0496e8ec91..a44532ec7c 100644 --- a/container/archive.go +++ b/container/archive.go @@ -52,7 +52,7 @@ func (container *Container) StatPath(resolvedPath, absPath string) (stat *types. } driver := container.BaseFS - lstat, err := driver.Lstat(resolvedPath) + lstat, err := os.Lstat(resolvedPath) if err != nil { return nil, err } diff --git a/daemon/archive.go b/daemon/archive.go index 03cfa51da6..c8e1cc7610 100644 --- a/daemon/archive.go +++ b/daemon/archive.go @@ -310,7 +310,7 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path return err } - stat, err := driver.Lstat(resolvedPath) + stat, err := os.Lstat(resolvedPath) if err != nil { return err } @@ -421,7 +421,7 @@ func (daemon *Daemon) containerCopy(container *container.Container, resource str if err != nil { return nil, err } - stat, err := driver.Stat(basePath) + stat, err := os.Stat(basePath) if err != nil { return nil, err } diff --git a/daemon/graphdriver/graphtest/graphbench_unix.go b/daemon/graphdriver/graphtest/graphbench_unix.go index 1e9e4fe407..6d55d1a1ef 100644 --- a/daemon/graphdriver/graphtest/graphbench_unix.go +++ b/daemon/graphdriver/graphtest/graphbench_unix.go @@ -5,10 +5,10 @@ package graphtest // import "github.com/docker/docker/daemon/graphdriver/graphte import ( "io" + "os" "path/filepath" "testing" - contdriver "github.com/containerd/continuity/driver" "github.com/docker/docker/pkg/stringid" "gotest.tools/v3/assert" ) @@ -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 := contdriver.ReadFile(root, filepath.Join(root.Path(), "testfile.txt")) + c, err := os.ReadFile(filepath.Join(root.Path(), "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 8b6a6bf971..7a9ca26778 100644 --- a/daemon/graphdriver/graphtest/graphtest_unix.go +++ b/daemon/graphdriver/graphtest/graphtest_unix.go @@ -99,7 +99,7 @@ func DriverTestCreateEmpty(t testing.TB, drivername string, driverOptions ...str verifyFile(t, dir.Path(), 0755|os.ModeDir, 0, 0) // Verify that the directory is empty - fis, err := readDir(dir, dir.Path()) + fis, err := readDir(dir.Path()) assert.NilError(t, err) assert.Check(t, is.Len(fis, 0)) diff --git a/daemon/graphdriver/graphtest/testutil.go b/daemon/graphdriver/graphtest/testutil.go index 24c6e705fe..17d9395fd5 100644 --- a/daemon/graphdriver/graphtest/testutil.go +++ b/daemon/graphdriver/graphtest/testutil.go @@ -3,12 +3,12 @@ package graphtest // import "github.com/docker/docker/daemon/graphdriver/graphte import ( "bytes" "fmt" + "io/fs" "math/rand" "os" "path/filepath" "sort" - "github.com/containerd/continuity/driver" "github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/stringid" @@ -36,17 +36,17 @@ func addFiles(drv graphdriver.Driver, layer string, seed int64) error { } defer drv.Put(layer) - if err := driver.WriteFile(root, filepath.Join(root.Path(), "file-a"), randomContent(64, seed), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root.Path(), "file-a"), randomContent(64, seed), 0755); err != nil { return err } - if err := root.MkdirAll(filepath.Join(root.Path(), "dir-b"), 0755); err != nil { + if err := os.MkdirAll(filepath.Join(root.Path(), "dir-b"), 0755); err != nil { return err } - if err := driver.WriteFile(root, filepath.Join(root.Path(), "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root.Path(), "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil { return err } - return driver.WriteFile(root, filepath.Join(root.Path(), "file-c"), randomContent(128*128, seed+2), 0755) + return os.WriteFile(filepath.Join(root.Path(), "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 := driver.ReadFile(root, filepath.Join(root.Path(), filename)) + fileContent, err := os.ReadFile(filepath.Join(root.Path(), 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 driver.WriteFile(root, filepath.Join(root.Path(), filename), content, 0755) + return os.WriteFile(filepath.Join(root.Path(), 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 root.MkdirAll(filepath.Join(root.Path(), dir), 0755) + return os.MkdirAll(filepath.Join(root.Path(), 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 := root.RemoveAll(filepath.Join(root.Path(), filename)); err != nil { + if err := os.RemoveAll(filepath.Join(root.Path(), filename)); err != nil { return err } } @@ -110,7 +110,7 @@ func checkFileRemoved(drv graphdriver.Driver, layer, filename string) error { } defer drv.Put(layer) - if _, err := root.Stat(filepath.Join(root.Path(), filename)); err == nil { + if _, err := os.Stat(filepath.Join(root.Path(), filename)); err == nil { return fmt.Errorf("file still exists: %s", filepath.Join(root.Path(), filename)) } else if !os.IsNotExist(err) { return err @@ -128,12 +128,12 @@ func addManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) e for i := 0; i < count; i += 100 { dir := filepath.Join(root.Path(), fmt.Sprintf("directory-%d", i)) - if err := root.MkdirAll(dir, 0755); err != nil { + if err := os.MkdirAll(dir, 0755); err != nil { return err } for j := 0; i+j < count && j < 100; j++ { file := filepath.Join(dir, fmt.Sprintf("file-%d", i+j)) - if err := driver.WriteFile(root, file, randomContent(64, seed+int64(i+j)), 0755); err != nil { + if err := os.WriteFile(file, randomContent(64, seed+int64(i+j)), 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 := root.MkdirAll(filepath.Join(root.Path(), archiveRoot), 0755); err != nil { + if err := os.MkdirAll(filepath.Join(root.Path(), 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 := driver.WriteFile(root, filepath.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root.Path(), 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 := driver.WriteFile(root, filepath.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root.Path(), 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 := root.Remove(filepath.Join(root.Path(), change.Path)); err != nil { + if err := os.Remove(filepath.Join(root.Path(), change.Path)); err != nil { return nil, err } } @@ -204,7 +204,7 @@ func checkManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) dir := filepath.Join(root.Path(), 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 := driver.ReadFile(root, file) + fileContent, err := os.ReadFile(file) if err != nil { return err } @@ -254,17 +254,17 @@ func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error { } defer drv.Put(layer) - if err := driver.WriteFile(root, filepath.Join(root.Path(), "top-id"), []byte(layer), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root.Path(), "top-id"), []byte(layer), 0755); err != nil { return err } layerDir := filepath.Join(root.Path(), fmt.Sprintf("layer-%d", i)) - if err := root.MkdirAll(layerDir, 0755); err != nil { + if err := os.MkdirAll(layerDir, 0755); err != nil { return err } - if err := driver.WriteFile(root, filepath.Join(layerDir, "layer-id"), []byte(layer), 0755); err != nil { + if err := os.WriteFile(filepath.Join(layerDir, "layer-id"), []byte(layer), 0755); err != nil { return err } - return driver.WriteFile(root, filepath.Join(layerDir, "parent-id"), []byte(parent), 0755) + return os.WriteFile(filepath.Join(layerDir, "parent-id"), []byte(parent), 0755) } func addManyLayers(drv graphdriver.Driver, baseLayer string, count int) (string, error) { @@ -291,7 +291,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error { } defer drv.Put(layer) - layerIDBytes, err := driver.ReadFile(root, filepath.Join(root.Path(), "top-id")) + layerIDBytes, err := os.ReadFile(filepath.Join(root.Path(), "top-id")) if err != nil { return err } @@ -303,14 +303,14 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error { for i := count; i > 0; i-- { layerDir := filepath.Join(root.Path(), fmt.Sprintf("layer-%d", i)) - thisLayerIDBytes, err := driver.ReadFile(root, filepath.Join(layerDir, "layer-id")) + thisLayerIDBytes, err := os.ReadFile(filepath.Join(layerDir, "layer-id")) if err != nil { return err } if !bytes.Equal(thisLayerIDBytes, layerIDBytes) { return fmt.Errorf("mismatched file content %v, expecting %v", thisLayerIDBytes, layerIDBytes) } - layerIDBytes, err = driver.ReadFile(root, filepath.Join(layerDir, "parent-id")) + layerIDBytes, err = os.ReadFile(filepath.Join(layerDir, "parent-id")) if err != nil { return err } @@ -318,11 +318,11 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error { return nil } -// readDir reads a directory just like driver.ReadDir() +// readDir reads a directory just like os.ReadDir() // then hides specific files (currently "lost+found") // so the tests don't "see" it -func readDir(r driver.Driver, dir string) ([]os.FileInfo, error) { - a, err := driver.ReadDir(r, dir) +func readDir(dir string) ([]fs.DirEntry, error) { + a, err := os.ReadDir(dir) if err != nil { return nil, err } diff --git a/daemon/graphdriver/graphtest/testutil_unix.go b/daemon/graphdriver/graphtest/testutil_unix.go index 236974ce14..164a18f4ca 100644 --- a/daemon/graphdriver/graphtest/testutil_unix.go +++ b/daemon/graphdriver/graphtest/testutil_unix.go @@ -46,11 +46,11 @@ func createBase(t testing.TB, driver graphdriver.Driver, name string) { defer driver.Put(name) subdir := filepath.Join(dirFS.Path(), "a subdir") - assert.NilError(t, dirFS.Mkdir(subdir, 0705|os.ModeSticky)) - assert.NilError(t, dirFS.Lchown(subdir, 1, 2)) + assert.NilError(t, os.Mkdir(subdir, 0705|os.ModeSticky)) + assert.NilError(t, contdriver.LocalDriver.Lchown(subdir, 1, 2)) file := filepath.Join(dirFS.Path(), "a file") - err = contdriver.WriteFile(dirFS, file, []byte("Some data"), 0222|os.ModeSetuid) + err = os.WriteFile(file, []byte("Some data"), 0222|os.ModeSetuid) assert.NilError(t, err) } @@ -65,7 +65,7 @@ func verifyBase(t testing.TB, driver graphdriver.Driver, name string) { file := filepath.Join(dirFS.Path(), "a file") verifyFile(t, file, 0222|os.ModeSetuid, 0, 0) - files, err := readDir(dirFS, dirFS.Path()) + files, err := readDir(dirFS.Path()) assert.NilError(t, err) assert.Check(t, is.Len(files, 2)) } diff --git a/layer/layer_test.go b/layer/layer_test.go index 6ccc52d925..dcb759c0b9 100644 --- a/layer/layer_test.go +++ b/layer/layer_test.go @@ -140,16 +140,16 @@ func newTestFile(name string, content []byte, perm os.FileMode) FileApplier { func (tf *testFile) ApplyFile(root containerfs.ContainerFS) error { fullPath := filepath.Join(root.Path(), tf.name) - if err := root.MkdirAll(filepath.Dir(fullPath), 0755); err != nil { + if err := os.MkdirAll(filepath.Dir(fullPath), 0755); err != nil { return err } // Check if already exists - if stat, err := root.Stat(fullPath); err == nil && stat.Mode().Perm() != tf.permission { - if err := root.Lchmod(fullPath, tf.permission); err != nil { + if stat, err := os.Stat(fullPath); err == nil && stat.Mode().Perm() != tf.permission { + if err := driver.LocalDriver.Lchmod(fullPath, tf.permission); err != nil { return err } } - return driver.WriteFile(root, fullPath, tf.content, tf.permission) + return os.WriteFile(fullPath, tf.content, tf.permission) } func initWithFiles(files ...FileApplier) layerInit { @@ -267,7 +267,7 @@ func TestMountAndRegister(t *testing.T) { t.Fatal(err) } - b, err := driver.ReadFile(path2, filepath.Join(path2.Path(), "testfile.txt")) + b, err := os.ReadFile(filepath.Join(path2.Path(), "testfile.txt")) if err != nil { t.Fatal(err) } @@ -375,7 +375,7 @@ func TestStoreRestore(t *testing.T) { t.Fatal(err) } - if err := driver.WriteFile(pathFS, filepath.Join(pathFS.Path(), "testfile.txt"), []byte("nothing here"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(pathFS.Path(), "testfile.txt"), []byte("nothing here"), 0644); err != nil { t.Fatal(err) } @@ -422,7 +422,7 @@ func TestStoreRestore(t *testing.T) { t.Fatal(err) } - b, err := driver.ReadFile(pathFS, filepath.Join(pathFS.Path(), "testfile.txt")) + b, err := os.ReadFile(filepath.Join(pathFS.Path(), "testfile.txt")) if err != nil { t.Fatal(err) } diff --git a/layer/mount_test.go b/layer/mount_test.go index 1778d16727..8b17afbe84 100644 --- a/layer/mount_test.go +++ b/layer/mount_test.go @@ -2,6 +2,7 @@ package layer // import "github.com/docker/docker/layer" import ( "io" + "os" "path/filepath" "runtime" "sort" @@ -46,12 +47,12 @@ func TestMountInit(t *testing.T) { t.Fatal(err) } - fi, err := pathFS.Stat(filepath.Join(pathFS.Path(), "testfile.txt")) + fi, err := os.Stat(filepath.Join(pathFS.Path(), "testfile.txt")) if err != nil { t.Fatal(err) } - f, err := pathFS.Open(filepath.Join(pathFS.Path(), "testfile.txt")) + f, err := os.Open(filepath.Join(pathFS.Path(), "testfile.txt")) if err != nil { t.Fatal(err) } @@ -106,7 +107,7 @@ func TestMountSize(t *testing.T) { t.Fatal(err) } - if err := driver.WriteFile(pathFS, filepath.Join(pathFS.Path(), "file2"), content2, 0755); err != nil { + if err := os.WriteFile(filepath.Join(pathFS.Path(), "file2"), content2, 0755); err != nil { t.Fatal(err) } @@ -158,23 +159,23 @@ func TestMountChanges(t *testing.T) { t.Fatal(err) } - if err := pathFS.Lchmod(filepath.Join(pathFS.Path(), "testfile1.txt"), 0755); err != nil { + if err := driver.LocalDriver.Lchmod(filepath.Join(pathFS.Path(), "testfile1.txt"), 0755); err != nil { t.Fatal(err) } - if err := driver.WriteFile(pathFS, filepath.Join(pathFS.Path(), "testfile1.txt"), []byte("mount data!"), 0755); err != nil { + if err := os.WriteFile(filepath.Join(pathFS.Path(), "testfile1.txt"), []byte("mount data!"), 0755); err != nil { t.Fatal(err) } - if err := pathFS.Remove(filepath.Join(pathFS.Path(), "testfile2.txt")); err != nil { + if err := os.Remove(filepath.Join(pathFS.Path(), "testfile2.txt")); err != nil { t.Fatal(err) } - if err := pathFS.Lchmod(filepath.Join(pathFS.Path(), "testfile3.txt"), 0755); err != nil { + if err := driver.LocalDriver.Lchmod(filepath.Join(pathFS.Path(), "testfile3.txt"), 0755); err != nil { t.Fatal(err) } - if err := driver.WriteFile(pathFS, filepath.Join(pathFS.Path(), "testfile4.txt"), []byte("mount data!"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(pathFS.Path(), "testfile4.txt"), []byte("mount data!"), 0644); err != nil { t.Fatal(err) } @@ -249,7 +250,7 @@ func TestMountApply(t *testing.T) { t.Fatal(err) } - f, err := pathFS.Open(filepath.Join(pathFS.Path(), "newfile.txt")) + f, err := os.Open(filepath.Join(pathFS.Path(), "newfile.txt")) if err != nil { t.Fatal(err) } diff --git a/pkg/containerfs/containerfs.go b/pkg/containerfs/containerfs.go index ddec1d3bf8..a3368a2caa 100644 --- a/pkg/containerfs/containerfs.go +++ b/pkg/containerfs/containerfs.go @@ -3,7 +3,6 @@ package containerfs // import "github.com/docker/docker/pkg/containerfs" import ( "path/filepath" - "github.com/containerd/continuity/driver" "github.com/moby/sys/symlink" ) @@ -12,23 +11,18 @@ type ContainerFS interface { // Path returns the path to the root. Note that this may not exist // on the local system, so the continuity operations must be used Path() string - - // Driver provides methods to manipulate files - driver.Driver } // 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 &local{ - path: path, - Driver: driver.LocalDriver, + path: path, } } type local struct { path string - driver.Driver } func (l *local) Path() string {