Skip to content

Commit

Permalink
Bugfix: handle parsing of favorites on gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Geens committed Nov 26, 2024
1 parent 683954c commit 558497c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/parse-favs-grpc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: handle parsing of favs over gRPC

To store user favorites, the key `user.http://owncloud.org/ns/favorite` maps to a list of users, in the format `u:username=1`. Right now, extracting the "correct" user doesn't happen in gRPC, while it is implemented in the EOS binary client. This feature has now been moved to the higher-level call in eosfs.

https://github.com/cs3org/reva/pull/4973
4 changes: 2 additions & 2 deletions internal/http/services/owncloud/ocdav/proppatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (s *svc) handleProppatch(ctx context.Context, w http.ResponseWriter, r *htt
HandleErrorStatus(&log, w, res.Status)
return nil, nil, false
}
if key == "http://owncloud.org/ns/favorite" {
if key == _propOcFavorite {
statRes, err := c.Stat(ctx, &provider.StatRequest{Ref: ref})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -269,7 +269,7 @@ func (s *svc) handleProppatch(ctx context.Context, w http.ResponseWriter, r *htt
acceptedProps = append(acceptedProps, propNameXML)
delete(sreq.ArbitraryMetadata.Metadata, key)

if key == "http://owncloud.org/ns/favorite" {
if key == _propOcFavorite {
statRes, err := c.Stat(ctx, &provider.StatRequest{Ref: ref})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down
44 changes: 8 additions & 36 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (c *Client) GetFileInfoByInode(ctx context.Context, auth eosclient.Authoriz
if err != nil {
return nil, err
}
info, err := c.parseFileInfo(ctx, stdout, true)
info, err := c.parseFileInfo(ctx, stdout)
if err != nil {
return nil, err
}
Expand All @@ -403,7 +403,7 @@ func (c *Client) GetFileInfoByFXID(ctx context.Context, auth eosclient.Authoriza
return nil, err
}

info, err := c.parseFileInfo(ctx, stdout, true)
info, err := c.parseFileInfo(ctx, stdout)
if err != nil {
return nil, err
}
Expand All @@ -418,7 +418,7 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, auth eosclient.Authoriza
if err != nil {
return nil, err
}
info, err := c.parseFileInfo(ctx, stdout, true)
info, err := c.parseFileInfo(ctx, stdout)
if err != nil {
return nil, err
}
Expand All @@ -442,7 +442,7 @@ func (c *Client) getRawFileInfoByPath(ctx context.Context, auth eosclient.Author
if err != nil {
return nil, err
}
return c.parseFileInfo(ctx, stdout, false)
return c.parseFileInfo(ctx, stdout)
}

func (c *Client) mergeACLsAndAttrsForFiles(ctx context.Context, auth eosclient.Authorization, info *eosclient.FileInfo) *eosclient.FileInfo {
Expand Down Expand Up @@ -970,7 +970,7 @@ func (c *Client) parseFind(ctx context.Context, auth eosclient.Authorization, di
if rl == "" {
continue
}
fi, err := c.parseFileInfo(ctx, rl, true)
fi, err := c.parseFileInfo(ctx, rl)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1071,7 +1071,7 @@ func (c *Client) parseQuota(path, raw string) (*eosclient.QuotaInfo, error) {
}

// TODO(labkode): better API to access extended attributes.
func (c *Client) parseFileInfo(ctx context.Context, raw string, parseFavoriteKey bool) (*eosclient.FileInfo, error) {
func (c *Client) parseFileInfo(ctx context.Context, raw string) (*eosclient.FileInfo, error) {
line := raw[15:]
index := strings.Index(line, " file=/")
lengthString := line[0:index]
Expand Down Expand Up @@ -1111,7 +1111,7 @@ func (c *Client) parseFileInfo(ctx context.Context, raw string, parseFavoriteKey
}
}
}
fi, err := c.mapToFileInfo(ctx, kv, attrs, parseFavoriteKey)
fi, err := c.mapToFileInfo(ctx, kv, attrs)
if err != nil {
return nil, err
}
Expand All @@ -1121,7 +1121,7 @@ func (c *Client) parseFileInfo(ctx context.Context, raw string, parseFavoriteKey
// mapToFileInfo converts the dictionary to an usable structure.
// The kv has format:
// map[sys.forced.space:default files:0 mode:42555 ino:5 sys.forced.blocksize:4k sys.forced.layout:replica uid:0 fid:5 sys.forced.blockchecksum:crc32c sys.recycle:/eos/backup/proc/recycle/ fxid:00000005 pid:1 etag:5:0.000 keylength.file:4 file:/eos treesize:1931593933849913 container:3 gid:0 mtime:1498571294.108614409 ctime:1460121992.294326762 pxid:00000001 sys.forced.checksum:adler sys.forced.nstripes:2].
func (c *Client) mapToFileInfo(ctx context.Context, kv, attrs map[string]string, parseFavoriteKey bool) (*eosclient.FileInfo, error) {
func (c *Client) mapToFileInfo(ctx context.Context, kv, attrs map[string]string) (*eosclient.FileInfo, error) {
inode, err := strconv.ParseUint(kv["ino"], 10, 64)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1225,11 +1225,6 @@ func (c *Client) mapToFileInfo(ctx context.Context, kv, attrs map[string]string,
return nil, err
}

// Read the favorite attr
if parseFavoriteKey {
parseAndSetFavoriteAttr(ctx, attrs)
}

fi := &eosclient.FileInfo{
File: kv["file"],
Inode: inode,
Expand All @@ -1255,26 +1250,3 @@ func (c *Client) mapToFileInfo(ctx context.Context, kv, attrs map[string]string,

return fi, nil
}

func parseAndSetFavoriteAttr(ctx context.Context, attrs map[string]string) {
// Read and correctly set the favorite attr
if user, ok := appctx.ContextGetUser(ctx); ok {
if favAttrStr, ok := attrs[favoritesKey]; ok {
favUsers, err := acl.Parse(favAttrStr, acl.ShortTextForm)
if err != nil {
return
}
for _, u := range favUsers.Entries {
// Check if the current user has favorited this resource
if u.Qualifier == user.Id.OpaqueId {
// Set attr val to 1
attrs[favoritesKey] = "1"
return
}
}
}
}

// Delete the favorite attr from the response
delete(attrs, favoritesKey)
}
26 changes: 26 additions & 0 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const (
lwShareAttrKey = "reva.lwshare" // used to store grants to lightweight accounts
lockPayloadKey = "reva.lockpayload" // used to store lock payloads
eosLockKey = "app.lock" // this is the key known by EOS to enforce a lock.
FavoritesKey = "http://owncloud.org/ns/favorite"
)

const (
Expand Down Expand Up @@ -2272,6 +2273,8 @@ func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo) (
}
}

parseAndSetFavoriteAttr(ctx, filteredAttrs)

info := &provider.ResourceInfo{
Id: &provider.ResourceId{OpaqueId: fmt.Sprintf("%d", eosFileInfo.Inode)},
Path: path,
Expand Down Expand Up @@ -2507,6 +2510,29 @@ func (fs *eosfs) getEosMetadata(finfo *eosclient.FileInfo) []byte {
return v
}

func parseAndSetFavoriteAttr(ctx context.Context, attrs map[string]string) {
// Read and correctly set the favorite attr
if user, ok := appctx.ContextGetUser(ctx); ok {
if favAttrStr, ok := attrs[FavoritesKey]; ok {
favUsers, err := acl.Parse(favAttrStr, acl.ShortTextForm)
if err != nil {
return
}
for _, u := range favUsers.Entries {
// Check if the current user has favorited this resource
if u.Qualifier == user.Id.OpaqueId {
// Set attr val to 1
attrs[FavoritesKey] = "1"
return
}
}
}
}

// Delete the favorite attr from the response
delete(attrs, FavoritesKey)
}

/*
Merge shadow on requests for /home ?
Expand Down

0 comments on commit 558497c

Please sign in to comment.