Skip to content

Commit

Permalink
Remove favs attribute if no favourites are set (#5017)
Browse files Browse the repository at this point in the history
Co-authored-by: Jesse Geens <[email protected]>
  • Loading branch information
jessegeens and Jesse Geens authored Dec 18, 2024
1 parent 6077fc7 commit 11dfcc3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-empty-fav-attr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: no empty favs attr

See issue #5016: we now unset the favs attr if no more favs are set

https://github.com/cs3org/reva/pull/5017
15 changes: 13 additions & 2 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,18 +527,29 @@ func (c *Client) handleFavAttr(ctx context.Context, auth eosclient.Authorization
favs.DeleteEntry(acl.TypeUser, u.Id.OpaqueId)
}
attr.Val = favs.Serialize()
return c.setEOSAttr(ctx, auth, attr, false, recursive, path, "")

if attr.Val == "" {
return c.unsetEOSAttr(ctx, auth, attr, recursive, path, "", true)
} else {
return c.setEOSAttr(ctx, auth, attr, false, recursive, path, "")
}
}

// UnsetAttr unsets an extended attribute on a path.
func (c *Client) UnsetAttr(ctx context.Context, auth eosclient.Authorization, attr *eosclient.Attribute, recursive bool, path, app string) error {
// In the case of handleFavs, we call unsetEOSAttr with deleteFavs = true, which is why this simply calls a subroutine
return c.unsetEOSAttr(ctx, auth, attr, recursive, path, app, false)
}

// UnsetAttr unsets an extended attribute on a path.
func (c *Client) unsetEOSAttr(ctx context.Context, auth eosclient.Authorization, attr *eosclient.Attribute, recursive bool, path, app string, deleteFavs bool) error {
if !isValidAttribute(attr) {
return errors.New("eos: attr is invalid: " + serializeAttribute(attr))
}

var err error
// Favorites need to be stored per user so handle these separately
if attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
if !deleteFavs && attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
info, err := c.getRawFileInfoByPath(ctx, auth, path)
if err != nil {
return err
Expand Down
15 changes: 12 additions & 3 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,16 +604,25 @@ func (c *Client) handleFavAttr(ctx context.Context, auth eosclient.Authorization
favs.DeleteEntry(acl.TypeUser, u.Id.OpaqueId)
}
attr.Val = favs.Serialize()
return c.setEOSAttr(ctx, auth, attr, false, recursive, path, "")
if attr.Val == "" {
return c.unsetEOSAttr(ctx, auth, attr, recursive, path, "", true)
} else {
return c.setEOSAttr(ctx, auth, attr, false, recursive, path, "")
}
}

// UnsetAttr unsets an extended attribute on a path.
func (c *Client) UnsetAttr(ctx context.Context, auth eosclient.Authorization, attr *eosclient.Attribute, recursive bool, path, app string) error {
// In the case of handleFavs, we call unsetEOSAttr with deleteFavs = true, which is why this simply calls a subroutine
return c.unsetEOSAttr(ctx, auth, attr, recursive, path, app, false)
}

func (c *Client) unsetEOSAttr(ctx context.Context, auth eosclient.Authorization, attr *eosclient.Attribute, recursive bool, path, app string, deleteFavs bool) error {
log := appctx.GetLogger(ctx)
log.Info().Str("func", "UnsetAttr").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")
log.Info().Str("func", "unsetEOSAttr").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

// Favorites need to be stored per user so handle these separately
if attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
if !deleteFavs && attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
info, err := c.GetFileInfoByPath(ctx, auth, path)
if err != nil {
return err
Expand Down

0 comments on commit 11dfcc3

Please sign in to comment.