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

owncloudsql: fix path, naming and listing spaces #4808

Merged
merged 1 commit into from
Aug 14, 2024
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
3 changes: 3 additions & 0 deletions changelog/unreleased/fix-owncloudsql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Fixed bugs in the owncloudsql storage driver

https://github.com/cs3org/reva/pull/4808
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20240425114016-d2cb31692b4e h1:Cm2l8m2riLa79eh7V2wHd1Ra7wR3TbngmeLZBJ9MxTU=
github.com/cs3org/go-cs3apis v0.0.0-20240425114016-d2cb31692b4e/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb h1:KmYZDReplv/yfwc1LNYpDcVhVujC3Pasv6WjXx1haSU=
github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
29 changes: 23 additions & 6 deletions pkg/storage/fs/owncloudsql/owncloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ func (fs *owncloudsqlfs) toDatabasePath(ip string) string {
return p
}

func (fs *owncloudsqlfs) toResourcePath(ip, owner string) string {
trim := filepath.Join(fs.c.DataDirectory, owner, "files")
p := strings.TrimPrefix(ip, trim)
p = strings.TrimPrefix(p, "/")
// root directory
if p == "" {
p = "."
}
return p
}

func (fs *owncloudsqlfs) toStoragePath(ctx context.Context, ip string) (sp string) {
if fs.c.EnableHome {
u := ctxpkg.ContextMustGetUser(ctx)
Expand Down Expand Up @@ -523,14 +534,15 @@ func (fs *owncloudsqlfs) convertToResourceInfo(ctx context.Context, entry *filec
if _, ok := mdKeysMap["*"]; len(mdKeys) == 0 || ok {
returnAllKeys = true
}

owner := fs.getOwner(ip)
path := fs.toResourcePath(ip, owner)
isDir := entry.MimeTypeString == "httpd/unix-directory"
ri := &provider.ResourceInfo{
Id: &provider.ResourceId{
// return ownclouds numeric storage id as the space id!
SpaceId: strconv.Itoa(entry.Storage), OpaqueId: strconv.Itoa(entry.ID),
},
Path: filepath.Base(ip),
Path: filepath.Base(path), // we currently only return the name, decomposedfs returns the path if the request was path based. is that even still possible?
Type: getResourceType(isDir),
Etag: entry.Etag,
MimeType: entry.MimeTypeString,
Expand All @@ -542,8 +554,16 @@ func (fs *owncloudsqlfs) convertToResourceInfo(ctx context.Context, entry *filec
Metadata: map[string]string{}, // TODO aduffeck: which metadata needs to go in here?
},
}
// omit parentid for root
if path != "." {
ri.Name = entry.Name
ri.ParentId = &provider.ResourceId{
// return ownclouds numeric storage id as the space id!
SpaceId: strconv.Itoa(entry.Storage), OpaqueId: strconv.Itoa(entry.Parent),
}
}

if owner, err := fs.getUser(ctx, fs.getOwner(ip)); err == nil {
if owner, err := fs.getUser(ctx, owner); err == nil {
ri.Owner = owner.Id
} else {
appctx.GetLogger(ctx).Error().Err(err).Msg("error getting owner")
Expand Down Expand Up @@ -1419,9 +1439,6 @@ func (fs *owncloudsqlfs) listWithNominalHome(ctx context.Context, ip string, mdK
finfos := []*provider.ResourceInfo{}
for _, entry := range entries {
cp := filepath.Join(fs.c.DataDirectory, owner, entry.Path)
if err != nil {
return nil, err
}
m, err := fs.convertToResourceInfo(ctx, entry, cp, mdKeys)
if err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("path", cp).Msg("error converting to a resource info")
Expand Down
11 changes: 10 additions & 1 deletion pkg/storage/fs/owncloudsql/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ import (
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/cs3org/reva/v2/pkg/storage/fs/owncloudsql/filecache"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
)

// ListStorageSpaces lists storage spaces according to the provided filters
func (fs *owncloudsqlfs) ListStorageSpaces(ctx context.Context, filter []*provider.ListStorageSpacesRequest_Filter, unrestricted bool) ([]*provider.StorageSpace, error) {
var (
spaceID = "*"
// uid *userpb.UserId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not yet. we need to implement the user filter in a subsequent pr. this PR just makes listing spaces and navigating files work again. I'm trying to make things work gradually...

)

filteringUnsupportedSpaceTypes := false
Expand All @@ -49,7 +51,7 @@ func (fs *owncloudsqlfs) ListStorageSpaces(ctx context.Context, filter []*provid
case provider.ListStorageSpacesRequest_Filter_TYPE_ID:
_, spaceID, _, _ = storagespace.SplitID(filter[i].GetId().OpaqueId)
case provider.ListStorageSpacesRequest_Filter_TYPE_USER:
_, spaceID, _, _ = storagespace.SplitID(filter[i].GetId().OpaqueId)
// uid = filter[i].GetUser()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one also

}
}
if filteringUnsupportedSpaceTypes {
Expand All @@ -63,6 +65,9 @@ func (fs *owncloudsqlfs) ListStorageSpaces(ctx context.Context, filter []*provid
if !ok {
return nil, errtypes.UserRequired("error getting user from context")
}
// if uid != nil && utils.UserIDEqual(uid, u.Id) {
// return nil, errtypes.PermissionDenied("cannot access space of other user?")
// }
Comment on lines +68 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this

space, err := fs.getPersonalSpace(ctx, u)
if err != nil {
return nil, err
Expand Down Expand Up @@ -141,6 +146,8 @@ func (fs *owncloudsqlfs) getPersonalSpace(ctx context.Context, owner *userpb.Use
Mtime: &types.Timestamp{Seconds: uint64(root.MTime)},
Owner: owner,
}
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "spaceAlias", "personal/"+owner.Username)
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "etag", fmt.Sprintf(`"%s"`, root.Etag))
return space, nil
}

Expand Down Expand Up @@ -179,5 +186,7 @@ func (fs *owncloudsqlfs) storageToSpace(ctx context.Context, storage *filecache.
Mtime: &types.Timestamp{Seconds: uint64(root.MTime)},
Owner: owner,
}
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "spaceAlias", "personal/"+owner.Username)
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "etag", fmt.Sprintf(`"%s"`, root.Etag))
return space, nil
}
5 changes: 5 additions & 0 deletions pkg/user/manager/owncloudsql/owncloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ func (m *manager) convertToCS3User(ctx context.Context, a *accounts.Account, ski
GidNumber: m.c.Nobody,
UidNumber: m.c.Nobody,
}
// https://github.com/cs3org/reva/pull/4135
// fall back to userid
if u.Id.OpaqueId == "" {
u.Id.OpaqueId = a.UserID
}
if u.Username == "" {
u.Username = u.Id.OpaqueId
}
Expand Down
Loading