1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

volume/local.New(): remove some intermediate variables

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-05-12 23:57:01 +02:00
parent 74be0fed6f
commit a4bfd9788f
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -47,25 +47,23 @@ type activeMount struct {
// is the base path that the Root instance uses to store its // is the base path that the Root instance uses to store its
// volumes. The base path is created here if it does not exist. // volumes. The base path is created here if it does not exist.
func New(scope string, rootIdentity idtools.Identity) (*Root, error) { func New(scope string, rootIdentity idtools.Identity) (*Root, error) {
rootDirectory := filepath.Join(scope, volumesPathName)
if err := idtools.MkdirAllAndChown(rootDirectory, 0701, idtools.CurrentIdentity()); err != nil {
return nil, err
}
r := &Root{ r := &Root{
path: rootDirectory, path: filepath.Join(scope, volumesPathName),
volumes: make(map[string]*localVolume), volumes: make(map[string]*localVolume),
rootIdentity: rootIdentity, rootIdentity: rootIdentity,
} }
dirs, err := os.ReadDir(rootDirectory) if err := idtools.MkdirAllAndChown(r.path, 0701, idtools.CurrentIdentity()); err != nil {
return nil, err
}
dirs, err := os.ReadDir(r.path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if r.quotaCtl, err = quota.NewControl(rootDirectory); err != nil { if r.quotaCtl, err = quota.NewControl(r.path); err != nil {
logrus.Debugf("No quota support for local volumes in %s: %v", rootDirectory, err) logrus.Debugf("No quota support for local volumes in %s: %v", r.path, err)
} }
for _, d := range dirs { for _, d := range dirs {
@ -81,8 +79,7 @@ func New(scope string, rootIdentity idtools.Identity) (*Root, error) {
quotaCtl: r.quotaCtl, quotaCtl: r.quotaCtl,
} }
r.volumes[name] = v r.volumes[name] = v
optsFilePath := filepath.Join(rootDirectory, name, "opts.json") if b, err := os.ReadFile(filepath.Join(r.path, name, "opts.json")); err == nil {
if b, err := os.ReadFile(optsFilePath); err == nil {
opts := optsConfig{} opts := optsConfig{}
if err := json.Unmarshal(b, &opts); err != nil { if err := json.Unmarshal(b, &opts); err != nil {
return nil, errors.Wrapf(err, "error while unmarshaling volume options for volume: %s", name) return nil, errors.Wrapf(err, "error while unmarshaling volume options for volume: %s", name)