diff --git a/volume/drivers/adapter.go b/volume/drivers/adapter.go index cd8f739d78..b6c6ad694c 100644 --- a/volume/drivers/adapter.go +++ b/volume/drivers/adapter.go @@ -10,9 +10,7 @@ import ( "github.com/docker/docker/volume" ) -var ( - errNoSuchVolume = errors.New("no such volume") -) +var errNoSuchVolume = errors.New("no such volume") type volumeDriverAdapter struct { name string @@ -168,6 +166,7 @@ func (a *volumeAdapter) Unmount(id string) error { func (a *volumeAdapter) CreatedAt() (time.Time, error) { return a.createdAt, nil } + func (a *volumeAdapter) Status() map[string]interface{} { out := make(map[string]interface{}, len(a.status)) for k, v := range a.status { diff --git a/volume/drivers/proxy.go b/volume/drivers/proxy.go index 8a44faeddc..b01e9861fb 100644 --- a/volume/drivers/proxy.go +++ b/volume/drivers/proxy.go @@ -170,8 +170,7 @@ func (pp *volumeDriverProxy) Unmount(name string, id string) (err error) { return } -type volumeDriverProxyListRequest struct { -} +type volumeDriverProxyListRequest struct{} type volumeDriverProxyListResponse struct { Volumes []*proxyVolume @@ -227,8 +226,7 @@ func (pp *volumeDriverProxy) Get(name string) (volume *proxyVolume, err error) { return } -type volumeDriverProxyCapabilitiesRequest struct { -} +type volumeDriverProxyCapabilitiesRequest struct{} type volumeDriverProxyCapabilitiesResponse struct { Capabilities volume.Capability diff --git a/volume/local/local.go b/volume/local/local.go index d3dcc59947..d7da589a2e 100644 --- a/volume/local/local.go +++ b/volume/local/local.go @@ -56,7 +56,7 @@ func New(scope string, rootIdentity idtools.Identity) (*Root, error) { rootIdentity: rootIdentity, } - if err := idtools.MkdirAllAndChown(r.path, 0701, idtools.CurrentIdentity()); err != nil { + if err := idtools.MkdirAllAndChown(r.path, 0o701, idtools.CurrentIdentity()); err != nil { return nil, err } @@ -151,12 +151,12 @@ func (r *Root) Create(name string, opts map[string]string) (volume.Volume, error } // Root dir does not need to be accessed by the remapped root - if err := idtools.MkdirAllAndChown(v.rootPath, 0701, idtools.CurrentIdentity()); err != nil { + if err := idtools.MkdirAllAndChown(v.rootPath, 0o701, idtools.CurrentIdentity()); err != nil { return nil, errors.Wrapf(errdefs.System(err), "error while creating volume root path '%s'", v.rootPath) } // Remapped root does need access to the data path - if err := idtools.MkdirAllAndChown(v.path, 0755, r.rootIdentity); err != nil { + if err := idtools.MkdirAllAndChown(v.path, 0o755, r.rootIdentity); err != nil { return nil, errors.Wrapf(errdefs.System(err), "error while creating volume data path '%s'", v.path) } @@ -372,7 +372,7 @@ func (v *localVolume) saveOpts() error { if err != nil { return err } - err = os.WriteFile(filepath.Join(v.rootPath, "opts.json"), b, 0600) + err = os.WriteFile(filepath.Join(v.rootPath, "opts.json"), b, 0o600) if err != nil { return errdefs.System(errors.Wrap(err, "error while persisting volume options")) } diff --git a/volume/local/local_linux_test.go b/volume/local/local_linux_test.go index c8688caff5..526a6ca257 100644 --- a/volume/local/local_linux_test.go +++ b/volume/local/local_linux_test.go @@ -15,8 +15,10 @@ import ( is "gotest.tools/v3/assert/cmp" ) -const quotaSize = 1024 * 1024 -const quotaSizeLiteral = "1M" +const ( + quotaSize = 1024 * 1024 + quotaSizeLiteral = "1M" +) func TestQuota(t *testing.T) { if msg, ok := quota.CanTestQuota(); !ok { @@ -59,11 +61,11 @@ func testVolWithQuota(t *testing.T, mountPoint, backingFsDev, testDir string) { testfile := filepath.Join(dir, "testfile") // test writing file smaller than quota - assert.NilError(t, os.WriteFile(testfile, make([]byte, quotaSize/2), 0644)) + assert.NilError(t, os.WriteFile(testfile, make([]byte, quotaSize/2), 0o644)) assert.NilError(t, os.Remove(testfile)) // test writing fiel larger than quota - err = os.WriteFile(testfile, make([]byte, quotaSize+1), 0644) + err = os.WriteFile(testfile, make([]byte, quotaSize+1), 0o644) assert.ErrorContains(t, err, "") if _, err := os.Stat(testfile); err == nil { assert.NilError(t, os.Remove(testfile)) diff --git a/volume/local/local_test.go b/volume/local/local_test.go index 5f8ccf7541..94cb354660 100644 --- a/volume/local/local_test.go +++ b/volume/local/local_test.go @@ -312,7 +312,7 @@ func TestRelaodNoOpts(t *testing.T) { t.Fatal(err) } // make sure a file with `null` (.e.g. empty opts map from older daemon) is ok - if err := os.WriteFile(filepath.Join(rootDir, "test2"), []byte("null"), 0600); err != nil { + if err := os.WriteFile(filepath.Join(rootDir, "test2"), []byte("null"), 0o600); err != nil { t.Fatal(err) } @@ -320,7 +320,7 @@ func TestRelaodNoOpts(t *testing.T) { t.Fatal(err) } // make sure an empty opts file doesn't break us too - if err := os.WriteFile(filepath.Join(rootDir, "test3"), nil, 0600); err != nil { + if err := os.WriteFile(filepath.Join(rootDir, "test3"), nil, 0o600); err != nil { t.Fatal(err) } diff --git a/volume/local/local_windows.go b/volume/local/local_windows.go index 43b89b3cb1..9eda81b514 100644 --- a/volume/local/local_windows.go +++ b/volume/local/local_windows.go @@ -33,6 +33,7 @@ func (v *localVolume) needsMount() bool { func (v *localVolume) mount() error { return nil } + func (v *localVolume) unmount() error { return nil } diff --git a/volume/mounts/linux_parser.go b/volume/mounts/linux_parser.go index be90157f94..d8139e5ef5 100644 --- a/volume/mounts/linux_parser.go +++ b/volume/mounts/linux_parser.go @@ -30,6 +30,7 @@ func linuxValidateNotRoot(p string) error { } return nil } + func linuxValidateAbsolute(p string) error { p = strings.ReplaceAll(p, `\`, `/`) if path.IsAbs(p) { @@ -37,12 +38,14 @@ func linuxValidateAbsolute(p string) error { } return fmt.Errorf("invalid mount path: '%s' mount path must be absolute", p) } + func (p *linuxParser) ValidateMountConfig(mnt *mount.Mount) error { // there was something looking like a bug in existing codebase: // - validateMountConfig on linux was called with options skipping bind source existence when calling ParseMountRaw // - but not when calling ParseMountSpec directly... nor when the unit test called it directly return p.validateMountConfigImpl(mnt, true) } + func (p *linuxParser) validateMountConfigImpl(mnt *mount.Mount, validateBindSourceExists bool) error { if len(mnt.Target) == 0 { return &errMountConfig{mnt, errMissingField("Target")} @@ -123,6 +126,7 @@ var linuxConsistencyModes = map[mount.Consistency]bool{ mount.ConsistencyCached: true, mount.ConsistencyDelegated: true, } + var linuxPropagationModes = map[mount.Propagation]bool{ mount.PropagationPrivate: true, mount.PropagationRPrivate: true, @@ -289,9 +293,11 @@ func (p *linuxParser) ParseMountRaw(raw, volumeDriver string) (*MountPoint, erro } return mp, err } + func (p *linuxParser) ParseMountSpec(cfg mount.Mount) (*MountPoint, error) { return p.parseMountSpec(cfg, true) } + func (p *linuxParser) parseMountSpec(cfg mount.Mount, validateBindSourceExists bool) (*MountPoint, error) { if err := p.validateMountConfigImpl(&cfg, validateBindSourceExists); err != nil { return nil, err @@ -415,6 +421,7 @@ func (p *linuxParser) ConvertTmpfsOptions(opt *mount.TmpfsOptions, readOnly bool func (p *linuxParser) DefaultCopyMode() bool { return true } + func (p *linuxParser) ValidateVolumeName(name string) error { return nil } diff --git a/volume/mounts/linux_parser_test.go b/volume/mounts/linux_parser_test.go index 12d57235b9..dff232a795 100644 --- a/volume/mounts/linux_parser_test.go +++ b/volume/mounts/linux_parser_test.go @@ -199,7 +199,7 @@ func TestConvertTmpfsOptions(t *testing.T) { } cases := []testCase{ { - opt: mount.TmpfsOptions{SizeBytes: 1024 * 1024, Mode: 0700}, + opt: mount.TmpfsOptions{SizeBytes: 1024 * 1024, Mode: 0o700}, readOnly: false, expectedSubstrings: []string{"size=1m", "mode=700"}, unexpectedSubstrings: []string{"ro"}, diff --git a/volume/mounts/mounts.go b/volume/mounts/mounts.go index bc90bb9def..188d693f88 100644 --- a/volume/mounts/mounts.go +++ b/volume/mounts/mounts.go @@ -156,7 +156,7 @@ func (m *MountPoint) Setup(mountLabel string, rootIDs idtools.Identity, checkFun // idtools.MkdirAllNewAs() produces an error if m.Source exists and is a file (not a directory) // also, makes sure that if the directory is created, the correct remapped rootUID/rootGID will own it - if err := idtools.MkdirAllAndChownNew(m.Source, 0755, rootIDs); err != nil { + if err := idtools.MkdirAllAndChownNew(m.Source, 0o755, rootIDs); err != nil { if perr, ok := err.(*os.PathError); ok { if perr.Err != syscall.ENOTDIR { return "", errors.Wrapf(err, "error while creating mount source path '%s'", m.Source) diff --git a/volume/mounts/validate.go b/volume/mounts/validate.go index 9fc9109021..f40438290d 100644 --- a/volume/mounts/validate.go +++ b/volume/mounts/validate.go @@ -23,6 +23,7 @@ func errBindSourceDoesNotExist(path string) error { func errExtraField(name string) error { return errors.Errorf("field %s must not be specified", name) } + func errMissingField(name string) error { return errors.Errorf("field %s must not be empty", name) } diff --git a/volume/mounts/windows_parser.go b/volume/mounts/windows_parser.go index 7800aa8c08..f9f0f08f44 100644 --- a/volume/mounts/windows_parser.go +++ b/volume/mounts/windows_parser.go @@ -191,6 +191,7 @@ func (p *windowsParser) ValidateVolumeName(name string) error { } return nil } + func (p *windowsParser) ValidateMountConfig(mnt *mount.Mount) error { return p.validateMountConfigReg(mnt, windowsValidators) } @@ -199,8 +200,7 @@ type fileInfoProvider interface { fileInfo(path string) (exist, isDir bool, err error) } -type defaultFileInfoProvider struct { -} +type defaultFileInfoProvider struct{} func (defaultFileInfoProvider) fileInfo(path string) (exist, isDir bool, err error) { fi, err := os.Stat(path) diff --git a/volume/service/db_test.go b/volume/service/db_test.go index 7770c1f3bc..cff19d5d0b 100644 --- a/volume/service/db_test.go +++ b/volume/service/db_test.go @@ -18,7 +18,7 @@ func TestSetGetMeta(t *testing.T) { assert.NilError(t, err) defer os.RemoveAll(dir) - db, err := bolt.Open(filepath.Join(dir, "db"), 0600, &bolt.Options{Timeout: 1 * time.Second}) + db, err := bolt.Open(filepath.Join(dir, "db"), 0o600, &bolt.Options{Timeout: 1 * time.Second}) assert.NilError(t, err) store := &VolumeStore{db: db} diff --git a/volume/service/service_linux_test.go b/volume/service/service_linux_test.go index d29aabe856..cc4a5539cc 100644 --- a/volume/service/service_linux_test.go +++ b/volume/service/service_linux_test.go @@ -41,9 +41,9 @@ func TestLocalVolumeSize(t *testing.T) { assert.NilError(t, err) data := make([]byte, 1024) - err = os.WriteFile(filepath.Join(v1.Mountpoint, "data"), data, 0644) + err = os.WriteFile(filepath.Join(v1.Mountpoint, "data"), data, 0o644) assert.NilError(t, err) - err = os.WriteFile(filepath.Join(v2.Mountpoint, "data"), data[:1], 0644) + err = os.WriteFile(filepath.Join(v2.Mountpoint, "data"), data[:1], 0o644) assert.NilError(t, err) ls, err := service.LocalVolumesSize(ctx) diff --git a/volume/service/store.go b/volume/service/store.go index 9ff8f53235..872b999bdb 100644 --- a/volume/service/store.go +++ b/volume/service/store.go @@ -99,13 +99,13 @@ func NewStore(rootPath string, drivers *drivers.Store, opts ...StoreOpt) (*Volum if rootPath != "" { // initialize metadata store volPath := filepath.Join(rootPath, volumeDataDir) - if err := os.MkdirAll(volPath, 0750); err != nil { + if err := os.MkdirAll(volPath, 0o750); err != nil { return nil, err } var err error dbPath := filepath.Join(volPath, "metadata.db") - vs.db, err = bolt.Open(dbPath, 0600, &bolt.Options{Timeout: 1 * time.Second}) + vs.db, err = bolt.Open(dbPath, 0o600, &bolt.Options{Timeout: 1 * time.Second}) if err != nil { return nil, errors.Wrapf(err, "error while opening volume store metadata database (%s)", dbPath) }