Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ownloudsql behave more like oc10 #1990

Merged
merged 4 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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