volume: format code with gofumpt
Formatting the code with https://github.com/mvdan/gofumpt Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d2452c2102
commit
4c281fb29a
14 changed files with 34 additions and 26 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ func (v *localVolume) needsMount() bool {
|
|||
func (v *localVolume) mount() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *localVolume) unmount() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"},
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue