Skip to content

Commit

Permalink
Make ownloudsql behave more like oc10 (#1990)
Browse files Browse the repository at this point in the history
* Set proper permissions for base directories

* Do not use a . as the name for root entries

* Set the same fs permissions as oc10

* Add changelog
  • Loading branch information
aduffeck authored Aug 13, 2021
1 parent 756bdce commit 674976a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/owncloudsql-oc10-compatibility.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Increase oc10 compatibility of owncloudsql

We added a few changes to the owncloudsql storage driver to behave more like oc10.

https://github.com/cs3org/reva/pull/1990
23 changes: 16 additions & 7 deletions pkg/storage/fs/owncloudsql/filecache/filecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,30 @@ func (c *Cache) doInsertOrUpdate(tx *sql.Tx, storage interface{}, data map[strin
}

path := data["path"].(string)
data["name"] = filepath.Base(path)
if data["name"] == "." {
data["name"] = ""
}

parentPath := strings.TrimRight(filepath.Dir(path), "/")
if parentPath == "." {
parentPath = ""
}
parent, err := c.Get(storageID, parentPath)
if err == nil {
data["parent"] = parent.ID
if path == "" {
data["parent"] = -1
} else {
if allowEmptyParent {
data["parent"] = -1
parent, err := c.Get(storageID, parentPath)
if err == nil {
data["parent"] = parent.ID
} else {
return -1, fmt.Errorf("could not find parent %s, %s, %v, %w", parentPath, path, parent, err)
if allowEmptyParent {
data["parent"] = -1
} else {
return -1, fmt.Errorf("could not find parent %s, %s, %v, %w", parentPath, path, parent, err)
}
}
}
data["name"] = filepath.Base(path)

if _, exists := data["checksum"]; !exists {
data["checksum"] = ""
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/storage/fs/owncloudsql/filecache/filecache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,23 @@ var _ = Describe("Filecache", func() {
Expect(entry.MimeType).To(Equal(9))
Expect(entry.MimePart).To(Equal(5))
})

It("does not add a . as the name for root entries", func() {
data := map[string]interface{}{
"path": "",
"checksum": "SHA1: abcdefg",
"etag": "abcdefg",
"mimetype": "image/tiff",
}

_, err := cache.InsertOrUpdate(1, data, false)
Expect(err).ToNot(HaveOccurred())

file, err := cache.Get(1, "")
Expect(err).ToNot(HaveOccurred())
Expect(file).ToNot(BeNil())
Expect(file.Name).To(Equal(""))
})
})

Context("when updating an existing record", func() {
Expand Down
9 changes: 5 additions & 4 deletions pkg/storage/fs/owncloudsql/owncloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ func (fs *owncloudsqlfs) createHomeForUser(ctx context.Context, user string) err
return err
}
for _, v := range homePaths {
if err := os.MkdirAll(v, 0700); err != nil {
if err := os.MkdirAll(v, 0755); err != nil {
return errors.Wrap(err, "owncloudsql: error creating home path: "+v)
}

Expand All @@ -679,9 +679,10 @@ func (fs *owncloudsqlfs) createHomeForUser(ctx context.Context, user string) err
return err
}
data := map[string]interface{}{
"path": fs.toDatabasePath(v),
"etag": calcEtag(ctx, fi),
"mimetype": "httpd/unix-directory",
"path": fs.toDatabasePath(v),
"etag": calcEtag(ctx, fi),
"mimetype": "httpd/unix-directory",
"permissions": 31, // 1: READ, 2: UPDATE, 4: CREATE, 8: DELETE, 16: SHARE
}

allowEmptyParent := v == filepath.Join(fs.c.DataDirectory, user) // the root doesn't have a parent
Expand Down

0 comments on commit 674976a

Please sign in to comment.