From c0f0cf6c19f9f6573b5db5b2c82adf9f5ea9c783 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 8 Oct 2020 00:25:49 +0200 Subject: [PATCH] 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 --- volume/local/local.go | 27 +++++++++++++++------------ volume/local/local_unix.go | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/volume/local/local.go b/volume/local/local.go index b13e8482ba..30923081db 100644 --- a/volume/local/local.go +++ b/volume/local/local.go @@ -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, ",") diff --git a/volume/local/local_unix.go b/volume/local/local_unix.go index 1c0a180c70..94dcc27f92 100644 --- a/volume/local/local_unix.go +++ b/volume/local/local_unix.go @@ -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) {