Skip to content

Commit 11dfcc3

Browse files
authored
Remove favs attribute if no favourites are set (#5017)
Co-authored-by: Jesse Geens <[email protected]>
1 parent 6077fc7 commit 11dfcc3

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bugfix: no empty favs attr
2+
3+
See issue #5016: we now unset the favs attr if no more favs are set
4+
5+
https://github.com/cs3org/reva/pull/5017

pkg/eosclient/eosbinary/eosbinary.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,18 +527,29 @@ func (c *Client) handleFavAttr(ctx context.Context, auth eosclient.Authorization
527527
favs.DeleteEntry(acl.TypeUser, u.Id.OpaqueId)
528528
}
529529
attr.Val = favs.Serialize()
530-
return c.setEOSAttr(ctx, auth, attr, false, recursive, path, "")
530+
531+
if attr.Val == "" {
532+
return c.unsetEOSAttr(ctx, auth, attr, recursive, path, "", true)
533+
} else {
534+
return c.setEOSAttr(ctx, auth, attr, false, recursive, path, "")
535+
}
531536
}
532537

533538
// UnsetAttr unsets an extended attribute on a path.
534539
func (c *Client) UnsetAttr(ctx context.Context, auth eosclient.Authorization, attr *eosclient.Attribute, recursive bool, path, app string) error {
540+
// In the case of handleFavs, we call unsetEOSAttr with deleteFavs = true, which is why this simply calls a subroutine
541+
return c.unsetEOSAttr(ctx, auth, attr, recursive, path, app, false)
542+
}
543+
544+
// UnsetAttr unsets an extended attribute on a path.
545+
func (c *Client) unsetEOSAttr(ctx context.Context, auth eosclient.Authorization, attr *eosclient.Attribute, recursive bool, path, app string, deleteFavs bool) error {
535546
if !isValidAttribute(attr) {
536547
return errors.New("eos: attr is invalid: " + serializeAttribute(attr))
537548
}
538549

539550
var err error
540551
// Favorites need to be stored per user so handle these separately
541-
if attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
552+
if !deleteFavs && attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
542553
info, err := c.getRawFileInfoByPath(ctx, auth, path)
543554
if err != nil {
544555
return err

pkg/eosclient/eosgrpc/eosgrpc.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,25 @@ func (c *Client) handleFavAttr(ctx context.Context, auth eosclient.Authorization
604604
favs.DeleteEntry(acl.TypeUser, u.Id.OpaqueId)
605605
}
606606
attr.Val = favs.Serialize()
607-
return c.setEOSAttr(ctx, auth, attr, false, recursive, path, "")
607+
if attr.Val == "" {
608+
return c.unsetEOSAttr(ctx, auth, attr, recursive, path, "", true)
609+
} else {
610+
return c.setEOSAttr(ctx, auth, attr, false, recursive, path, "")
611+
}
608612
}
609613

610614
// UnsetAttr unsets an extended attribute on a path.
611615
func (c *Client) UnsetAttr(ctx context.Context, auth eosclient.Authorization, attr *eosclient.Attribute, recursive bool, path, app string) error {
616+
// In the case of handleFavs, we call unsetEOSAttr with deleteFavs = true, which is why this simply calls a subroutine
617+
return c.unsetEOSAttr(ctx, auth, attr, recursive, path, app, false)
618+
}
619+
620+
func (c *Client) unsetEOSAttr(ctx context.Context, auth eosclient.Authorization, attr *eosclient.Attribute, recursive bool, path, app string, deleteFavs bool) error {
612621
log := appctx.GetLogger(ctx)
613-
log.Info().Str("func", "UnsetAttr").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")
622+
log.Info().Str("func", "unsetEOSAttr").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")
614623

615624
// Favorites need to be stored per user so handle these separately
616-
if attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
625+
if !deleteFavs && attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
617626
info, err := c.GetFileInfoByPath(ctx, auth, path)
618627
if err != nil {
619628
return err

0 commit comments

Comments
 (0)