Skip to content

Commit

Permalink
owncloudsql: fix path, naming and listing spaces
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Aug 14, 2024
1 parent 548644c commit 3ef9e6f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
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
3 changes: 2 additions & 1 deletion internal/grpc/services/gateway/authprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func (s *svc) WhoAmI(ctx context.Context, req *gateway.WhoAmIRequest) (*gateway.
}

func (s *svc) findAuthProvider(ctx context.Context, authType string) (authpb.ProviderAPIClient, error) {
c, err := pool.GetAuthRegistryServiceClient(s.c.AuthRegistryEndpoint)
log := appctx.GetLogger(ctx)
c, err := pool.GetAuthRegistryServiceClient(s.c.AuthRegistryEndpoint, pool.WithLogger(log))
if err != nil {
err = errors.Wrap(err, "gateway: error getting auth registry client")
return nil, err
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
)

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()
}
}
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?")
// }
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

0 comments on commit 3ef9e6f

Please sign in to comment.