volume/local: extract saving options to a separate method
Differentiate between Windows and Linux, as Windows doesn't support options, so there's no need to save options to disk, Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d3930330a7
commit
c0f0cf6c19
2 changed files with 16 additions and 13 deletions
|
@ -169,18 +169,8 @@ func (r *Root) Create(name string, opts map[string]string) (volume.Volume, error
|
|||
}
|
||||
}()
|
||||
|
||||
if len(opts) != 0 {
|
||||
if err = v.setOpts(opts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var b []byte
|
||||
b, err = json.Marshal(v.opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = os.WriteFile(filepath.Join(v.rootPath, "opts.json"), b, 0600); err != nil {
|
||||
return nil, errdefs.System(errors.Wrap(err, "error while persisting volume options"))
|
||||
}
|
||||
if err = v.setOpts(opts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.volumes[name] = v
|
||||
|
@ -352,6 +342,19 @@ func (v *localVolume) Status() map[string]interface{} {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (v *localVolume) saveOpts() error {
|
||||
var b []byte
|
||||
b, err := json.Marshal(v.opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.WriteFile(filepath.Join(v.rootPath, "opts.json"), b, 0600)
|
||||
if err != nil {
|
||||
return errdefs.System(errors.Wrap(err, "error while persisting volume options"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// getAddress finds out address/hostname from options
|
||||
func getAddress(opts string) string {
|
||||
optsList := strings.Split(opts, ",")
|
||||
|
|
|
@ -96,7 +96,7 @@ func (v *localVolume) setOpts(opts map[string]string) error {
|
|||
}
|
||||
v.opts.Quota.Size = uint64(size)
|
||||
}
|
||||
return nil
|
||||
return v.saveOpts()
|
||||
}
|
||||
|
||||
func unmount(path string) {
|
||||
|
|
Loading…
Reference in a new issue