diff --git a/volume/drivers/adapter.go b/volume/drivers/adapter.go index cd8f739d78093e31a41831004efef2615145894a..b6c6ad694cde7e705740110e233a0d8681d1fcf6 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 8a44faeddcf73736802c8e742083ecb1b37fc6bb..b01e9861fb7ab5e4195533132e377f229352414f 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 d3dcc59947bfb6cf7a237708eb75b0bf0a33aadc..d7da589a2eb894c034e46b14c2af936c6a3a19f0 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 c8688caff5601e994977b85f0cae4b5475f68c9d..526a6ca257739670faf205423fffcd80a08c6e7b 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 5f8ccf75416b3526437b74eb7175b28ce03063c1..94cb3546609892bc20a9f3c831fd9bad3644ace7 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 43b89b3cb15d5b0f31ec0ff8c41016f40df798ca..9eda81b514eab2488ea02fafd5ec8591be62f1d8 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 be90157f94631413e8eaf638a8f344e3e06a3549..d8139e5ef5743998d2cc8258809350b241f63951 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 12d57235b9b2c33a7143070abd4e9886bc172edc..dff232a795cf4f610a4d6b300f3c75e8a1ae08fd 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 bc90bb9def9de5f10c2f94b59c39f635524f23c2..188d693f8836d932edc8b4c23316e5ab6e1d6c4c 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 9fc91090219d4733533d9c41ece23cc2709f3452..f40438290d1253fd85522d7107bc9f3be050a85c 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 7800aa8c083da4d567c9d3c457df649ad5a044be..f9f0f08f44d8a839ae22a76f0d06af7d6f3c15f1 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 7770c1f3bcfe55d0f68d95aabddc0fe7bb853ffc..cff19d5d0bd59c5d4e3c831b7bd06b5358169200 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 d29aabe856dc74aee48e8f041ba6da0ec92c31b0..cc4a5539ccf33404ce8d42e5d1abf41d75138475 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 9ff8f532359995af5329dd358615a131e1034d08..872b999bdbb79005d1a82c027b4f2b14f4469f15 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) }