Skip to content

Commit 2862bcd

Browse files
committed
owncloudsql: fix path, naming and listing spaces
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
1 parent 548644c commit 2862bcd

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Bugfix: Fixed bugs in the owncloudsql storage driver
2+
3+
https://github.com/cs3org/reva/pull/4808

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
916916
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
917917
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
918918
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
919-
github.com/cs3org/go-cs3apis v0.0.0-20240425114016-d2cb31692b4e h1:Cm2l8m2riLa79eh7V2wHd1Ra7wR3TbngmeLZBJ9MxTU=
920-
github.com/cs3org/go-cs3apis v0.0.0-20240425114016-d2cb31692b4e/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
921919
github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb h1:KmYZDReplv/yfwc1LNYpDcVhVujC3Pasv6WjXx1haSU=
922920
github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
923921
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pkg/storage/fs/owncloudsql/owncloudsql.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,17 @@ func (fs *owncloudsqlfs) toDatabasePath(ip string) string {
309309
return p
310310
}
311311

312+
func (fs *owncloudsqlfs) toResourcePath(ip, owner string) string {
313+
trim := filepath.Join(fs.c.DataDirectory, owner, "files")
314+
p := strings.TrimPrefix(ip, trim)
315+
p = strings.TrimPrefix(p, "/")
316+
// root directory
317+
if p == "" {
318+
p = "."
319+
}
320+
return p
321+
}
322+
312323
func (fs *owncloudsqlfs) toStoragePath(ctx context.Context, ip string) (sp string) {
313324
if fs.c.EnableHome {
314325
u := ctxpkg.ContextMustGetUser(ctx)
@@ -523,14 +534,15 @@ func (fs *owncloudsqlfs) convertToResourceInfo(ctx context.Context, entry *filec
523534
if _, ok := mdKeysMap["*"]; len(mdKeys) == 0 || ok {
524535
returnAllKeys = true
525536
}
526-
537+
owner := fs.getOwner(ip)
538+
path := fs.toResourcePath(ip, owner)
527539
isDir := entry.MimeTypeString == "httpd/unix-directory"
528540
ri := &provider.ResourceInfo{
529541
Id: &provider.ResourceId{
530542
// return ownclouds numeric storage id as the space id!
531543
SpaceId: strconv.Itoa(entry.Storage), OpaqueId: strconv.Itoa(entry.ID),
532544
},
533-
Path: filepath.Base(ip),
545+
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?
534546
Type: getResourceType(isDir),
535547
Etag: entry.Etag,
536548
MimeType: entry.MimeTypeString,
@@ -542,8 +554,16 @@ func (fs *owncloudsqlfs) convertToResourceInfo(ctx context.Context, entry *filec
542554
Metadata: map[string]string{}, // TODO aduffeck: which metadata needs to go in here?
543555
},
544556
}
557+
// omit parentid for root
558+
if path != "." {
559+
ri.Name = entry.Name
560+
ri.ParentId = &provider.ResourceId{
561+
// return ownclouds numeric storage id as the space id!
562+
SpaceId: strconv.Itoa(entry.Storage), OpaqueId: strconv.Itoa(entry.Parent),
563+
}
564+
}
545565

546-
if owner, err := fs.getUser(ctx, fs.getOwner(ip)); err == nil {
566+
if owner, err := fs.getUser(ctx, owner); err == nil {
547567
ri.Owner = owner.Id
548568
} else {
549569
appctx.GetLogger(ctx).Error().Err(err).Msg("error getting owner")
@@ -1419,9 +1439,6 @@ func (fs *owncloudsqlfs) listWithNominalHome(ctx context.Context, ip string, mdK
14191439
finfos := []*provider.ResourceInfo{}
14201440
for _, entry := range entries {
14211441
cp := filepath.Join(fs.c.DataDirectory, owner, entry.Path)
1422-
if err != nil {
1423-
return nil, err
1424-
}
14251442
m, err := fs.convertToResourceInfo(ctx, entry, cp, mdKeys)
14261443
if err != nil {
14271444
appctx.GetLogger(ctx).Error().Err(err).Str("path", cp).Msg("error converting to a resource info")

pkg/storage/fs/owncloudsql/spaces.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ import (
3131
"github.com/cs3org/reva/v2/pkg/errtypes"
3232
"github.com/cs3org/reva/v2/pkg/storage/fs/owncloudsql/filecache"
3333
"github.com/cs3org/reva/v2/pkg/storagespace"
34+
"github.com/cs3org/reva/v2/pkg/utils"
3435
)
3536

3637
// ListStorageSpaces lists storage spaces according to the provided filters
3738
func (fs *owncloudsqlfs) ListStorageSpaces(ctx context.Context, filter []*provider.ListStorageSpacesRequest_Filter, unrestricted bool) ([]*provider.StorageSpace, error) {
3839
var (
3940
spaceID = "*"
41+
// uid *userpb.UserId
4042
)
4143

4244
filteringUnsupportedSpaceTypes := false
@@ -49,7 +51,7 @@ func (fs *owncloudsqlfs) ListStorageSpaces(ctx context.Context, filter []*provid
4951
case provider.ListStorageSpacesRequest_Filter_TYPE_ID:
5052
_, spaceID, _, _ = storagespace.SplitID(filter[i].GetId().OpaqueId)
5153
case provider.ListStorageSpacesRequest_Filter_TYPE_USER:
52-
_, spaceID, _, _ = storagespace.SplitID(filter[i].GetId().OpaqueId)
54+
// uid = filter[i].GetUser()
5355
}
5456
}
5557
if filteringUnsupportedSpaceTypes {
@@ -63,6 +65,9 @@ func (fs *owncloudsqlfs) ListStorageSpaces(ctx context.Context, filter []*provid
6365
if !ok {
6466
return nil, errtypes.UserRequired("error getting user from context")
6567
}
68+
// if uid != nil && utils.UserIDEqual(uid, u.Id) {
69+
// return nil, errtypes.PermissionDenied("cannot access space of other user?")
70+
// }
6671
space, err := fs.getPersonalSpace(ctx, u)
6772
if err != nil {
6873
return nil, err
@@ -141,6 +146,8 @@ func (fs *owncloudsqlfs) getPersonalSpace(ctx context.Context, owner *userpb.Use
141146
Mtime: &types.Timestamp{Seconds: uint64(root.MTime)},
142147
Owner: owner,
143148
}
149+
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "spaceAlias", "personal/"+owner.Username)
150+
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "etag", fmt.Sprintf(`"%s"`, root.Etag))
144151
return space, nil
145152
}
146153

@@ -179,5 +186,7 @@ func (fs *owncloudsqlfs) storageToSpace(ctx context.Context, storage *filecache.
179186
Mtime: &types.Timestamp{Seconds: uint64(root.MTime)},
180187
Owner: owner,
181188
}
189+
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "spaceAlias", "personal/"+owner.Username)
190+
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "etag", fmt.Sprintf(`"%s"`, root.Etag))
182191
return space, nil
183192
}

pkg/user/manager/owncloudsql/owncloudsql.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ func (m *manager) convertToCS3User(ctx context.Context, a *accounts.Account, ski
167167
GidNumber: m.c.Nobody,
168168
UidNumber: m.c.Nobody,
169169
}
170+
// https://github.com/cs3org/reva/pull/4135
171+
// fall back to userid
172+
if u.Id.OpaqueId == "" {
173+
u.Id.OpaqueId = a.UserID
174+
}
170175
if u.Username == "" {
171176
u.Username = u.Id.OpaqueId
172177
}

0 commit comments

Comments
 (0)