diff --git a/daemon/graphdriver/btrfs/btrfs.go b/daemon/graphdriver/btrfs/btrfs.go index 1b82b01c1a..700fb8d7e5 100644 --- a/daemon/graphdriver/btrfs/btrfs.go +++ b/daemon/graphdriver/btrfs/btrfs.go @@ -83,7 +83,7 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr GID: idMap.RootPair().GID, } - if err := idtools.MkdirAllAndChown(home, 0710, dirID); err != nil { + if err := idtools.MkdirAllAndChown(home, 0o710, dirID); err != nil { return nil, err } @@ -237,7 +237,7 @@ func subvolSnapshot(src, dest, name string) error { var args C.struct_btrfs_ioctl_vol_args_v2 args.fd = C.__s64(getDirFd(srcDir)) - var cs = C.CString(name) + cs := C.CString(name) C.set_name_btrfs_ioctl_vol_args_v2(&args, cs) free(cs) @@ -495,7 +495,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error { GID: root.GID, } - if err := idtools.MkdirAllAndChown(subvolumes, 0710, dirID); err != nil { + if err := idtools.MkdirAllAndChown(subvolumes, 0o710, dirID); err != nil { return err } if parent == "" { @@ -530,10 +530,10 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error { if err := d.setStorageSize(path.Join(subvolumes, id), driver); err != nil { return err } - if err := idtools.MkdirAllAndChown(quotas, 0700, idtools.CurrentIdentity()); err != nil { + if err := idtools.MkdirAllAndChown(quotas, 0o700, idtools.CurrentIdentity()); err != nil { return err } - if err := os.WriteFile(path.Join(quotas, id), []byte(fmt.Sprint(driver.options.size)), 0644); err != nil { + if err := os.WriteFile(path.Join(quotas, id), []byte(fmt.Sprint(driver.options.size)), 0o644); err != nil { return err } } diff --git a/daemon/graphdriver/copy/copy_test.go b/daemon/graphdriver/copy/copy_test.go index 8dcd8d9d56..34067bc0c3 100644 --- a/daemon/graphdriver/copy/copy_test.go +++ b/daemon/graphdriver/copy/copy_test.go @@ -94,7 +94,7 @@ func populateSrcDir(t *testing.T, srcDir string, remainingDepth int) { for i := 0; i < 10; i++ { dirName := filepath.Join(srcDir, fmt.Sprintf("srcdir-%d", i)) // Owner all bits set - assert.NilError(t, os.Mkdir(dirName, randomMode(0700))) + assert.NilError(t, os.Mkdir(dirName, randomMode(0o700))) populateSrcDir(t, dirName, remainingDepth-1) assert.NilError(t, system.Chtimes(dirName, aTime, mTime)) } @@ -102,7 +102,7 @@ func populateSrcDir(t *testing.T, srcDir string, remainingDepth int) { for i := 0; i < 10; i++ { fileName := filepath.Join(srcDir, fmt.Sprintf("srcfile-%d", i)) // Owner read bit set - assert.NilError(t, os.WriteFile(fileName, []byte{}, randomMode(0400))) + assert.NilError(t, os.WriteFile(fileName, []byte{}, randomMode(0o400))) assert.NilError(t, system.Chtimes(fileName, aTime, mTime)) } } @@ -118,7 +118,7 @@ func doCopyTest(t *testing.T, copyWithFileRange, copyWithFileClone *bool) { buf := make([]byte, 1024) _, err = r.Read(buf) assert.NilError(t, err) - assert.NilError(t, os.WriteFile(srcFilename, buf, 0777)) + assert.NilError(t, os.WriteFile(srcFilename, buf, 0o777)) fileinfo, err := os.Stat(srcFilename) assert.NilError(t, err) @@ -143,7 +143,7 @@ func TestCopyHardlink(t *testing.T) { srcFile2 := filepath.Join(srcDir, "file2") dstFile1 := filepath.Join(dstDir, "file1") dstFile2 := filepath.Join(dstDir, "file2") - assert.NilError(t, os.WriteFile(srcFile1, []byte{}, 0777)) + assert.NilError(t, os.WriteFile(srcFile1, []byte{}, 0o777)) assert.NilError(t, os.Link(srcFile1, srcFile2)) assert.Check(t, DirCopy(srcDir, dstDir, Content, false)) diff --git a/daemon/graphdriver/driver.go b/daemon/graphdriver/driver.go index ce64fb1ddc..7be7cbc1df 100644 --- a/daemon/graphdriver/driver.go +++ b/daemon/graphdriver/driver.go @@ -24,10 +24,8 @@ const ( FsMagicUnsupported = FsMagic(0x00000000) ) -var ( - // All registered drivers - drivers map[string]InitFunc -) +// All registered drivers +var drivers map[string]InitFunc // CreateOpts contains optional arguments for Create() and CreateReadWrite() // methods. diff --git a/daemon/graphdriver/driver_freebsd.go b/daemon/graphdriver/driver_freebsd.go index cd83c4e21a..5591e3f187 100644 --- a/daemon/graphdriver/driver_freebsd.go +++ b/daemon/graphdriver/driver_freebsd.go @@ -6,10 +6,8 @@ import ( "golang.org/x/sys/unix" ) -var ( - // List of drivers that should be used in an order - priority = "zfs" -) +// List of drivers that should be used in an order +var priority = "zfs" // Mounted checks if the given path is mounted as the fs type func Mounted(fsType FsMagic, mountPath string) (bool, error) { diff --git a/daemon/graphdriver/driver_linux.go b/daemon/graphdriver/driver_linux.go index f3b0afb9d4..5fc3158113 100644 --- a/daemon/graphdriver/driver_linux.go +++ b/daemon/graphdriver/driver_linux.go @@ -109,8 +109,7 @@ func NewDefaultChecker() Checker { return &defaultChecker{} } -type defaultChecker struct { -} +type defaultChecker struct{} func (c *defaultChecker) IsMounted(path string) bool { m, _ := mountinfo.Mounted(path) diff --git a/daemon/graphdriver/driver_test.go b/daemon/graphdriver/driver_test.go index b2f4d80502..fe0653b30b 100644 --- a/daemon/graphdriver/driver_test.go +++ b/daemon/graphdriver/driver_test.go @@ -14,19 +14,19 @@ func TestIsEmptyDir(t *testing.T) { defer os.RemoveAll(tmp) d := filepath.Join(tmp, "empty-dir") - err = os.Mkdir(d, 0755) + err = os.Mkdir(d, 0o755) assert.NilError(t, err) empty := isEmptyDir(d) assert.Check(t, empty) d = filepath.Join(tmp, "dir-with-subdir") - err = os.MkdirAll(filepath.Join(d, "subdir"), 0755) + err = os.MkdirAll(filepath.Join(d, "subdir"), 0o755) assert.NilError(t, err) empty = isEmptyDir(d) assert.Check(t, !empty) d = filepath.Join(tmp, "dir-with-empty-file") - err = os.Mkdir(d, 0755) + err = os.Mkdir(d, 0o755) assert.NilError(t, err) f, err := os.CreateTemp(d, "file") assert.NilError(t, err) diff --git a/daemon/graphdriver/driver_unsupported.go b/daemon/graphdriver/driver_unsupported.go index ada47f9aaa..3100bcb57b 100644 --- a/daemon/graphdriver/driver_unsupported.go +++ b/daemon/graphdriver/driver_unsupported.go @@ -2,10 +2,8 @@ package graphdriver // import "github.com/docker/docker/daemon/graphdriver" -var ( - // List of drivers that should be used in an order - priority = "unsupported" -) +// List of drivers that should be used in an order +var priority = "unsupported" // GetFSMagic returns the filesystem id given the path. func GetFSMagic(rootpath string) (FsMagic, error) { diff --git a/daemon/graphdriver/driver_windows.go b/daemon/graphdriver/driver_windows.go index 856b575e75..e6470290df 100644 --- a/daemon/graphdriver/driver_windows.go +++ b/daemon/graphdriver/driver_windows.go @@ -1,9 +1,7 @@ package graphdriver // import "github.com/docker/docker/daemon/graphdriver" -var ( - // List of drivers that should be used in order - priority = "windowsfilter" -) +// List of drivers that should be used in order +var priority = "windowsfilter" // GetFSMagic returns the filesystem id given the path. func GetFSMagic(rootpath string) (FsMagic, error) { diff --git a/daemon/graphdriver/fsdiff.go b/daemon/graphdriver/fsdiff.go index a43c5203b0..64c6551e94 100644 --- a/daemon/graphdriver/fsdiff.go +++ b/daemon/graphdriver/fsdiff.go @@ -12,11 +12,9 @@ import ( "github.com/docker/docker/pkg/ioutils" ) -var ( - // ApplyUncompressedLayer defines the unpack method used by the graph - // driver. - ApplyUncompressedLayer = chrootarchive.ApplyUncompressedLayer -) +// ApplyUncompressedLayer defines the unpack method used by the graph +// driver. +var ApplyUncompressedLayer = chrootarchive.ApplyUncompressedLayer // NaiveDiffDriver takes a ProtoDriver and adds the // capability of the Diffing methods on the local file system, @@ -41,8 +39,10 @@ type NaiveDiffDriver struct { // ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error) // DiffSize(id, parent string) (size int64, err error) func NewNaiveDiffDriver(driver ProtoDriver, idMap idtools.IdentityMapping) Driver { - return &NaiveDiffDriver{ProtoDriver: driver, - IDMap: idMap} + return &NaiveDiffDriver{ + ProtoDriver: driver, + IDMap: idMap, + } } // Diff produces an archive of the changes between the specified diff --git a/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go b/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go index 176fd1bb8e..addc3045b7 100644 --- a/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go +++ b/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go @@ -30,10 +30,8 @@ import ( "golang.org/x/sys/unix" ) -var ( - // untar defines the untar method - untar = chrootarchive.UntarUncompressed -) +// untar defines the untar method +var untar = chrootarchive.UntarUncompressed const ( driverName = "fuse-overlayfs" @@ -65,9 +63,7 @@ type Driver struct { locker *locker.Locker } -var ( - logger = log.G(context.TODO()).WithField("storage-driver", driverName) -) +var logger = log.G(context.TODO()).WithField("storage-driver", driverName) func init() { graphdriver.Register(driverName, Init) @@ -91,10 +87,10 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr GID: idMap.RootPair().GID, } - if err := idtools.MkdirAllAndChown(home, 0710, dirID); err != nil { + if err := idtools.MkdirAllAndChown(home, 0o710, dirID); err != nil { return nil, err } - if err := idtools.MkdirAllAndChown(path.Join(home, linkDir), 0700, currentID); err != nil { + if err := idtools.MkdirAllAndChown(path.Join(home, linkDir), 0o700, currentID); err != nil { return nil, err } @@ -173,10 +169,10 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr dir := d.dir(id) root := d.idMap.RootPair() - if err := idtools.MkdirAllAndChown(path.Dir(dir), 0710, root); err != nil { + if err := idtools.MkdirAllAndChown(path.Dir(dir), 0o710, root); err != nil { return err } - if err := idtools.MkdirAndChown(dir, 0710, root); err != nil { + if err := idtools.MkdirAndChown(dir, 0o710, root); err != nil { return err } @@ -191,7 +187,7 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr return fmt.Errorf("--storage-opt is not supported") } - if err := idtools.MkdirAndChown(path.Join(dir, diffDirName), 0755, root); err != nil { + if err := idtools.MkdirAndChown(path.Join(dir, diffDirName), 0o755, root); err != nil { return err } @@ -201,7 +197,7 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr } // Write link id to link file - if err := os.WriteFile(path.Join(dir, "link"), []byte(lid), 0644); err != nil { + if err := os.WriteFile(path.Join(dir, "link"), []byte(lid), 0o644); err != nil { return err } @@ -210,11 +206,11 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr return nil } - if err := idtools.MkdirAndChown(path.Join(dir, workDirName), 0710, root); err != nil { + if err := idtools.MkdirAndChown(path.Join(dir, workDirName), 0o710, root); err != nil { return err } - if err := os.WriteFile(path.Join(d.dir(parent), "committed"), []byte{}, 0600); err != nil { + if err := os.WriteFile(path.Join(d.dir(parent), "committed"), []byte{}, 0o600); err != nil { return err } @@ -223,7 +219,7 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr return err } if lower != "" { - if err := os.WriteFile(path.Join(dir, lowerFile), []byte(lower), 0666); err != nil { + if err := os.WriteFile(path.Join(dir, lowerFile), []byte(lower), 0o666); err != nil { return err } } @@ -363,7 +359,7 @@ func (d *Driver) Get(id, mountLabel string) (_ string, retErr error) { mountData := label.FormatMountLabel(opts, mountLabel) mountTarget := mergedDir - if err := idtools.MkdirAndChown(mergedDir, 0700, d.idMap.RootPair()); err != nil { + if err := idtools.MkdirAndChown(mergedDir, 0o700, d.idMap.RootPair()); err != nil { return "", err } diff --git a/daemon/graphdriver/graphtest/graphtest_unix.go b/daemon/graphdriver/graphtest/graphtest_unix.go index 5e64f0efa3..e85971180f 100644 --- a/daemon/graphdriver/graphtest/graphtest_unix.go +++ b/daemon/graphdriver/graphtest/graphtest_unix.go @@ -18,9 +18,7 @@ import ( is "gotest.tools/v3/assert/cmp" ) -var ( - drv *Driver -) +var drv *Driver // Driver conforms to graphdriver.Driver interface and // contains information such as root and reference count of the number of clients using it. @@ -35,7 +33,7 @@ func newDriver(t testing.TB, name string, options []string) *Driver { root, err := os.MkdirTemp("", "docker-graphtest-") assert.NilError(t, err) - assert.NilError(t, os.MkdirAll(root, 0755)) + assert.NilError(t, os.MkdirAll(root, 0o755)) d, err := graphdriver.GetDriver(name, nil, graphdriver.Options{DriverOptions: options, Root: root}) if err != nil { t.Logf("graphdriver: %v\n", err) @@ -95,7 +93,7 @@ func DriverTestCreateEmpty(t testing.TB, drivername string, driverOptions ...str dir, err := driver.Get("empty", "") assert.NilError(t, err) - verifyFile(t, dir, 0755|os.ModeDir, 0, 0) + verifyFile(t, dir, 0o755|os.ModeDir, 0, 0) // Verify that the directory is empty fis, err := readDir(dir) @@ -296,7 +294,7 @@ func writeRandomFile(path string, size uint64) error { if err != nil { return err } - return os.WriteFile(path, data, 0700) + return os.WriteFile(path, data, 0o700) } // DriverTestSetQuota Create a driver and test setting quota. diff --git a/daemon/graphdriver/graphtest/testutil.go b/daemon/graphdriver/graphtest/testutil.go index bf4fb5a576..2cba5343ae 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(root, "file-a"), randomContent(64, seed), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root, "file-a"), randomContent(64, seed), 0o755); err != nil { return err } - if err := os.MkdirAll(filepath.Join(root, "dir-b"), 0755); err != nil { + if err := os.MkdirAll(filepath.Join(root, "dir-b"), 0o755); err != nil { return err } - if err := os.WriteFile(filepath.Join(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), 0o755); err != nil { return err } - return os.WriteFile(filepath.Join(root, "file-c"), randomContent(128*128, seed+2), 0755) + return os.WriteFile(filepath.Join(root, "file-c"), randomContent(128*128, seed+2), 0o755) } func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) error { @@ -75,7 +75,7 @@ func addFile(drv graphdriver.Driver, layer, filename string, content []byte) err } defer drv.Put(layer) - return os.WriteFile(filepath.Join(root, filename), content, 0755) + return os.WriteFile(filepath.Join(root, filename), content, 0o755) } 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(root, dir), 0755) + return os.MkdirAll(filepath.Join(root, dir), 0o755) } func removeAll(drv graphdriver.Driver, layer string, names ...string) error { @@ -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, fmt.Sprintf("directory-%d", i)) - if err := os.MkdirAll(dir, 0755); err != nil { + if err := os.MkdirAll(dir, 0o755); 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 := os.WriteFile(file, randomContent(64, seed+int64(i+j)), 0755); err != nil { + if err := os.WriteFile(file, randomContent(64, seed+int64(i+j)), 0o755); 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(root, archiveRoot), 0755); err != nil { + if err := os.MkdirAll(filepath.Join(root, archiveRoot), 0o755); err != nil { return nil, err } for j := 0; i+j < count && j < 100; j++ { @@ -168,14 +168,14 @@ 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(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)), 0o755); 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(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)), 0o755); err != nil { return nil, err } // Remove file @@ -254,17 +254,17 @@ func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error { } defer drv.Put(layer) - if err := os.WriteFile(filepath.Join(root, "top-id"), []byte(layer), 0755); err != nil { + if err := os.WriteFile(filepath.Join(root, "top-id"), []byte(layer), 0o755); err != nil { return err } layerDir := filepath.Join(root, fmt.Sprintf("layer-%d", i)) - if err := os.MkdirAll(layerDir, 0755); err != nil { + if err := os.MkdirAll(layerDir, 0o755); err != nil { return err } - if err := os.WriteFile(filepath.Join(layerDir, "layer-id"), []byte(layer), 0755); err != nil { + if err := os.WriteFile(filepath.Join(layerDir, "layer-id"), []byte(layer), 0o755); err != nil { return err } - return os.WriteFile(filepath.Join(layerDir, "parent-id"), []byte(parent), 0755) + return os.WriteFile(filepath.Join(layerDir, "parent-id"), []byte(parent), 0o755) } func addManyLayers(drv graphdriver.Driver, baseLayer string, count int) (string, error) { diff --git a/daemon/graphdriver/graphtest/testutil_unix.go b/daemon/graphdriver/graphtest/testutil_unix.go index 127e2ba8e4..54514938fb 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) { defer driver.Put(name) subdir := filepath.Join(dirFS, "a subdir") - assert.NilError(t, os.Mkdir(subdir, 0705|os.ModeSticky)) + assert.NilError(t, os.Mkdir(subdir, 0o705|os.ModeSticky)) assert.NilError(t, contdriver.LocalDriver.Lchown(subdir, 1, 2)) file := filepath.Join(dirFS, "a file") - err = os.WriteFile(file, []byte("Some data"), 0222|os.ModeSetuid) + err = os.WriteFile(file, []byte("Some data"), 0o222|os.ModeSetuid) assert.NilError(t, err) } @@ -59,10 +59,10 @@ func verifyBase(t testing.TB, driver graphdriver.Driver, name string) { defer driver.Put(name) subdir := filepath.Join(dirFS, "a subdir") - verifyFile(t, subdir, 0705|os.ModeDir|os.ModeSticky, 1, 2) + verifyFile(t, subdir, 0o705|os.ModeDir|os.ModeSticky, 1, 2) file := filepath.Join(dirFS, "a file") - verifyFile(t, file, 0222|os.ModeSetuid, 0, 0) + verifyFile(t, file, 0o222|os.ModeSetuid, 0, 0) files, err := readDir(dirFS) assert.NilError(t, err) diff --git a/daemon/graphdriver/overlay2/check.go b/daemon/graphdriver/overlay2/check.go index a617b798a5..d9c35dac62 100644 --- a/daemon/graphdriver/overlay2/check.go +++ b/daemon/graphdriver/overlay2/check.go @@ -40,22 +40,22 @@ func doesSupportNativeDiff(d string) error { }() // Make directories l1/d, l1/d1, l2/d, l3, work, merged - if err := os.MkdirAll(filepath.Join(td, "l1", "d"), 0755); err != nil { + if err := os.MkdirAll(filepath.Join(td, "l1", "d"), 0o755); err != nil { return err } - if err := os.MkdirAll(filepath.Join(td, "l1", "d1"), 0755); err != nil { + if err := os.MkdirAll(filepath.Join(td, "l1", "d1"), 0o755); err != nil { return err } - if err := os.MkdirAll(filepath.Join(td, "l2", "d"), 0755); err != nil { + if err := os.MkdirAll(filepath.Join(td, "l2", "d"), 0o755); err != nil { return err } - if err := os.Mkdir(filepath.Join(td, "l3"), 0755); err != nil { + if err := os.Mkdir(filepath.Join(td, "l3"), 0o755); err != nil { return err } - if err := os.Mkdir(filepath.Join(td, workDirName), 0755); err != nil { + if err := os.Mkdir(filepath.Join(td, workDirName), 0o755); err != nil { return err } - if err := os.Mkdir(filepath.Join(td, mergedDirName), 0755); err != nil { + if err := os.Mkdir(filepath.Join(td, mergedDirName), 0o755); err != nil { return err } @@ -75,7 +75,7 @@ func doesSupportNativeDiff(d string) error { }() // Touch file in d to force copy up of opaque directory "d" from "l2" to "l3" - if err := os.WriteFile(filepath.Join(td, mergedDirName, "d", "f"), []byte{}, 0644); err != nil { + if err := os.WriteFile(filepath.Join(td, mergedDirName, "d", "f"), []byte{}, 0o644); err != nil { return errors.Wrap(err, "failed to write to merged directory") } @@ -149,13 +149,13 @@ func usingMetacopy(d string) (bool, error) { l1, l2, work, merged := filepath.Join(td, "l1"), filepath.Join(td, "l2"), filepath.Join(td, "work"), filepath.Join(td, "merged") for _, dir := range []string{l1, l2, work, merged} { - if err := os.Mkdir(dir, 0755); err != nil { + if err := os.Mkdir(dir, 0o755); err != nil { return false, err } } // Create empty file in l1 with 0700 permissions for metacopy test - if err := os.WriteFile(filepath.Join(l1, "f"), []byte{}, 0700); err != nil { + if err := os.WriteFile(filepath.Join(l1, "f"), []byte{}, 0o700); err != nil { return false, err } @@ -180,7 +180,7 @@ func usingMetacopy(d string) (bool, error) { }() // Make a change that only impacts the inode, in the upperdir - if err := os.Chmod(filepath.Join(merged, "f"), 0600); err != nil { + if err := os.Chmod(filepath.Join(merged, "f"), 0o600); err != nil { return false, errors.Wrap(err, "error changing permissions on file for metacopy check") } diff --git a/daemon/graphdriver/overlay2/overlay.go b/daemon/graphdriver/overlay2/overlay.go index 663625fb84..73d87d9690 100644 --- a/daemon/graphdriver/overlay2/overlay.go +++ b/daemon/graphdriver/overlay2/overlay.go @@ -32,10 +32,8 @@ import ( "golang.org/x/sys/unix" ) -var ( - // untar defines the untar method - untar = chrootarchive.UntarUncompressed -) +// untar defines the untar method +var untar = chrootarchive.UntarUncompressed // This backend uses the overlay union filesystem for containers // with diff directories for each layer. @@ -168,10 +166,10 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr UID: cur.UID, GID: idMap.RootPair().GID, } - if err := idtools.MkdirAllAndChown(home, 0710, dirID); err != nil { + if err := idtools.MkdirAllAndChown(home, 0o710, dirID); err != nil { return nil, err } - if err := idtools.MkdirAllAndChown(path.Join(home, linkDir), 0700, cur); err != nil { + if err := idtools.MkdirAllAndChown(path.Join(home, linkDir), 0o700, cur); err != nil { return nil, err } @@ -347,10 +345,10 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr GID: root.GID, } - if err := idtools.MkdirAllAndChown(path.Dir(dir), 0710, dirID); err != nil { + if err := idtools.MkdirAllAndChown(path.Dir(dir), 0o710, dirID); err != nil { return err } - if err := idtools.MkdirAndChown(dir, 0710, dirID); err != nil { + if err := idtools.MkdirAndChown(dir, 0o710, dirID); err != nil { return err } @@ -375,7 +373,7 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr } } - if err := idtools.MkdirAndChown(path.Join(dir, diffDirName), 0755, root); err != nil { + if err := idtools.MkdirAndChown(path.Join(dir, diffDirName), 0o755, root); err != nil { return err } @@ -385,7 +383,7 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr } // Write link id to link file - if err := os.WriteFile(path.Join(dir, "link"), []byte(lid), 0644); err != nil { + if err := os.WriteFile(path.Join(dir, "link"), []byte(lid), 0o644); err != nil { return err } @@ -394,11 +392,11 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr return nil } - if err := idtools.MkdirAndChown(path.Join(dir, workDirName), 0700, root); err != nil { + if err := idtools.MkdirAndChown(path.Join(dir, workDirName), 0o700, root); err != nil { return err } - if err := os.WriteFile(path.Join(d.dir(parent), "committed"), []byte{}, 0600); err != nil { + if err := os.WriteFile(path.Join(d.dir(parent), "committed"), []byte{}, 0o600); err != nil { return err } @@ -407,7 +405,7 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr return err } if lower != "" { - if err := os.WriteFile(path.Join(dir, lowerFile), []byte(lower), 0666); err != nil { + if err := os.WriteFile(path.Join(dir, lowerFile), []byte(lower), 0o666); err != nil { return err } } @@ -567,7 +565,7 @@ func (d *Driver) Get(id, mountLabel string) (_ string, retErr error) { mountTarget := mergedDir root := d.idMap.RootPair() - if err := idtools.MkdirAndChown(mergedDir, 0700, root); err != nil { + if err := idtools.MkdirAndChown(mergedDir, 0o700, root); err != nil { return "", err } diff --git a/daemon/graphdriver/overlayutils/overlayutils.go b/daemon/graphdriver/overlayutils/overlayutils.go index 4235be3d6e..f7cc0de0d1 100644 --- a/daemon/graphdriver/overlayutils/overlayutils.go +++ b/daemon/graphdriver/overlayutils/overlayutils.go @@ -60,7 +60,7 @@ func SupportsOverlay(d string, checkMultipleLowers bool) error { }() for _, dir := range []string{"lower1", "lower2", "upper", "work", "merged"} { - if err := os.Mkdir(filepath.Join(td, dir), 0755); err != nil { + if err := os.Mkdir(filepath.Join(td, dir), 0o755); err != nil { return err } } diff --git a/daemon/graphdriver/overlayutils/userxattr.go b/daemon/graphdriver/overlayutils/userxattr.go index 173007cda9..f2139709ff 100644 --- a/daemon/graphdriver/overlayutils/userxattr.go +++ b/daemon/graphdriver/overlayutils/userxattr.go @@ -71,7 +71,7 @@ func NeedsUserXAttr(d string) (bool, error) { log.G(context.TODO()).WithError(err).Warnf("Failed to remove check directory %v", tdRoot) } - if err := os.MkdirAll(tdRoot, 0700); err != nil { + if err := os.MkdirAll(tdRoot, 0o700); err != nil { return false, err } @@ -87,7 +87,7 @@ func NeedsUserXAttr(d string) (bool, error) { } for _, dir := range []string{"lower1", "lower2", "upper", "work", "merged"} { - if err := os.Mkdir(filepath.Join(td, dir), 0755); err != nil { + if err := os.Mkdir(filepath.Join(td, dir), 0o755); err != nil { return false, err } } diff --git a/daemon/graphdriver/vfs/driver.go b/daemon/graphdriver/vfs/driver.go index 8803b4bf2f..06f471fc39 100644 --- a/daemon/graphdriver/vfs/driver.go +++ b/daemon/graphdriver/vfs/driver.go @@ -21,10 +21,8 @@ const ( bestEffortXattrsOptValue = "i_want_broken_containers" ) -var ( - // CopyDir defines the copy method to use. - CopyDir = dirCopy -) +// CopyDir defines the copy method to use. +var CopyDir = dirCopy func init() { graphdriver.Register("vfs", Init) @@ -46,7 +44,7 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr UID: idtools.CurrentIdentity().UID, GID: d.idMapping.RootPair().GID, } - if err := idtools.MkdirAllAndChown(home, 0710, dirID); err != nil { + if err := idtools.MkdirAllAndChown(home, 0o710, dirID); err != nil { return nil, err } @@ -170,10 +168,10 @@ func (d *Driver) create(id, parent string, size uint64) error { UID: idtools.CurrentIdentity().UID, GID: rootIDs.GID, } - if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0710, dirID); err != nil { + if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0o710, dirID); err != nil { return err } - if err := idtools.MkdirAndChown(dir, 0755, rootIDs); err != nil { + if err := idtools.MkdirAndChown(dir, 0o755, rootIDs); err != nil { return err } diff --git a/daemon/graphdriver/vfs/quota_unsupported.go b/daemon/graphdriver/vfs/quota_unsupported.go index ce414aa146..05f54182e2 100644 --- a/daemon/graphdriver/vfs/quota_unsupported.go +++ b/daemon/graphdriver/vfs/quota_unsupported.go @@ -4,8 +4,7 @@ package vfs // import "github.com/docker/docker/daemon/graphdriver/vfs" import "github.com/docker/docker/quota" -type driverQuota struct { -} +type driverQuota struct{} func setupDriverQuota(driver *Driver) error { return nil diff --git a/daemon/graphdriver/windows/windows.go b/daemon/graphdriver/windows/windows.go index 4090f8af0f..fa9a23548d 100644 --- a/daemon/graphdriver/windows/windows.go +++ b/daemon/graphdriver/windows/windows.go @@ -73,8 +73,7 @@ func init() { } } -type checker struct { -} +type checker struct{} func (c *checker) IsMounted(path string) bool { return false @@ -846,7 +845,7 @@ func (d *Driver) resolveID(id string) (string, error) { // setID stores the layerId in disk. func (d *Driver) setID(id, altID string) error { - return os.WriteFile(filepath.Join(d.dir(id), "layerId"), []byte(altID), 0600) + return os.WriteFile(filepath.Join(d.dir(id), "layerId"), []byte(altID), 0o600) } // getLayerChain returns the layer chain information. diff --git a/daemon/graphdriver/zfs/zfs.go b/daemon/graphdriver/zfs/zfs.go index c1c426572d..8af76a384f 100644 --- a/daemon/graphdriver/zfs/zfs.go +++ b/daemon/graphdriver/zfs/zfs.go @@ -56,7 +56,7 @@ func Init(base string, opt []string, idMap idtools.IdentityMapping) (graphdriver return nil, graphdriver.ErrPrerequisites } - file, err := os.OpenFile("/dev/zfs", os.O_RDWR, 0600) + file, err := os.OpenFile("/dev/zfs", os.O_RDWR, 0o600) if err != nil { logger.Debugf("cannot open /dev/zfs: %v", err) return nil, graphdriver.ErrPrerequisites @@ -109,7 +109,7 @@ func Init(base string, opt []string, idMap idtools.IdentityMapping) (graphdriver UID: idtools.CurrentIdentity().UID, GID: idMap.RootPair().GID, } - if err := idtools.MkdirAllAndChown(base, 0710, dirID); err != nil { + if err := idtools.MkdirAllAndChown(base, 0o710, dirID); err != nil { return nil, fmt.Errorf("Failed to create '%s': %v", base, err) } @@ -388,7 +388,7 @@ func (d *Driver) Get(id, mountLabel string) (_ string, retErr error) { root := d.idMap.RootPair() // Create the target directories if they don't exist - if err := idtools.MkdirAllAndChown(mountpoint, 0755, root); err != nil { + if err := idtools.MkdirAllAndChown(mountpoint, 0o755, root); err != nil { return "", err } diff --git a/daemon/graphdriver/zfs/zfs_freebsd.go b/daemon/graphdriver/zfs/zfs_freebsd.go index 6f2269bed9..eafe6ea8e0 100644 --- a/daemon/graphdriver/zfs/zfs_freebsd.go +++ b/daemon/graphdriver/zfs/zfs_freebsd.go @@ -3,8 +3,8 @@ package zfs // import "github.com/docker/docker/daemon/graphdriver/zfs" import ( "strings" - "github.com/docker/docker/daemon/graphdriver" "github.com/containerd/containerd/log" + "github.com/docker/docker/daemon/graphdriver" "golang.org/x/sys/unix" )