From 2862bcd40445d142b44f2dd82a4d6737326c163d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 31 Jul 2024 14:51:59 +0200 Subject: [PATCH] owncloudsql: fix path, naming and listing spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/fix-owncloudsql.md | 3 +++ go.sum | 2 -- pkg/storage/fs/owncloudsql/owncloudsql.go | 29 ++++++++++++++++----- pkg/storage/fs/owncloudsql/spaces.go | 11 +++++++- pkg/user/manager/owncloudsql/owncloudsql.go | 5 ++++ 5 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 changelog/unreleased/fix-owncloudsql.md diff --git a/changelog/unreleased/fix-owncloudsql.md b/changelog/unreleased/fix-owncloudsql.md new file mode 100644 index 0000000000..a6934a6a96 --- /dev/null +++ b/changelog/unreleased/fix-owncloudsql.md @@ -0,0 +1,3 @@ +Bugfix: Fixed bugs in the owncloudsql storage driver + +https://github.com/cs3org/reva/pull/4808 diff --git a/go.sum b/go.sum index 9dc3d395b0..23949906c0 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/storage/fs/owncloudsql/owncloudsql.go b/pkg/storage/fs/owncloudsql/owncloudsql.go index 67ba812393..0c51f1c552 100644 --- a/pkg/storage/fs/owncloudsql/owncloudsql.go +++ b/pkg/storage/fs/owncloudsql/owncloudsql.go @@ -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) @@ -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, @@ -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") @@ -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") diff --git a/pkg/storage/fs/owncloudsql/spaces.go b/pkg/storage/fs/owncloudsql/spaces.go index 05bd1644a2..eb2d88c398 100644 --- a/pkg/storage/fs/owncloudsql/spaces.go +++ b/pkg/storage/fs/owncloudsql/spaces.go @@ -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 ) filteringUnsupportedSpaceTypes := false @@ -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() } } if filteringUnsupportedSpaceTypes { @@ -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?") + // } space, err := fs.getPersonalSpace(ctx, u) if err != nil { return nil, err @@ -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 } @@ -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 } diff --git a/pkg/user/manager/owncloudsql/owncloudsql.go b/pkg/user/manager/owncloudsql/owncloudsql.go index 166bdc8c7a..c61d485f6d 100644 --- a/pkg/user/manager/owncloudsql/owncloudsql.go +++ b/pkg/user/manager/owncloudsql/owncloudsql.go @@ -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 }