From 3ea2fc5092c32befd9244bb6ce074cafbb649ed4 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Mon, 6 Jul 2020 18:06:42 +0200 Subject: [PATCH] fix initialization of shares json file Signed-off-by: David Christofas --- .../unreleased/fix-json-sharemanager-initialization.md | 8 ++++++++ pkg/share/manager/json/json.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/fix-json-sharemanager-initialization.md diff --git a/changelog/unreleased/fix-json-sharemanager-initialization.md b/changelog/unreleased/fix-json-sharemanager-initialization.md new file mode 100644 index 0000000000..87838c72b8 --- /dev/null +++ b/changelog/unreleased/fix-json-sharemanager-initialization.md @@ -0,0 +1,8 @@ +Bugfix: Fix initialization of json share manager + +When an empty shares.json file existed the json share manager would fail while +trying to unmarshal the empty file. + +https://github.com/cs3org/reva/issues/941 +https://github.com/cs3org/reva/pull/940 + diff --git a/pkg/share/manager/json/json.go b/pkg/share/manager/json/json.go index 4096a715a4..0a5d20ea03 100644 --- a/pkg/share/manager/json/json.go +++ b/pkg/share/manager/json/json.go @@ -70,8 +70,8 @@ func New(m map[string]interface{}) (share.Manager, error) { } func loadOrCreate(file string) (*shareModel, error) { - _, err := os.Stat(file) - if os.IsNotExist(err) { + info, err := os.Stat(file) + if os.IsNotExist(err) || info.Size() == 0 { if err := ioutil.WriteFile(file, []byte("{}"), 0700); err != nil { err = errors.Wrap(err, "error opening/creating the file: "+file) return nil, err