Skip to content

Commit

Permalink
Merge pull request cs3org#4808 from butonic/fix-owncloudsql
Browse files Browse the repository at this point in the history
owncloudsql: fix path, naming and listing spaces
  • Loading branch information
butonic authored Aug 14, 2024
2 parents dce7872 + 2862bcd commit 80a9ca5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 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
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 80a9ca5

Please sign in to comment.