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