From 9c1a73bcc0b49c4f120cbc142a8ba9d8aa0b8ed9 Mon Sep 17 00:00:00 2001 From: Jesse Geens Date: Wed, 18 Dec 2024 13:22:35 +0100 Subject: [PATCH] Remove favs attribute if no favourites are set --- changelog/unreleased/fix-empty-fav-attr.md | 5 +++++ pkg/eosclient/eosbinary/eosbinary.go | 15 +++++++++++++-- pkg/eosclient/eosgrpc/eosgrpc.go | 15 ++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 changelog/unreleased/fix-empty-fav-attr.md diff --git a/changelog/unreleased/fix-empty-fav-attr.md b/changelog/unreleased/fix-empty-fav-attr.md new file mode 100644 index 0000000000..221c50f587 --- /dev/null +++ b/changelog/unreleased/fix-empty-fav-attr.md @@ -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 \ No newline at end of file diff --git a/pkg/eosclient/eosbinary/eosbinary.go b/pkg/eosclient/eosbinary/eosbinary.go index ff9b2d407d..1541735246 100644 --- a/pkg/eosclient/eosbinary/eosbinary.go +++ b/pkg/eosclient/eosbinary/eosbinary.go @@ -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 diff --git a/pkg/eosclient/eosgrpc/eosgrpc.go b/pkg/eosclient/eosgrpc/eosgrpc.go index c2ca7a8d78..3eb409094c 100644 --- a/pkg/eosclient/eosgrpc/eosgrpc.go +++ b/pkg/eosclient/eosgrpc/eosgrpc.go @@ -597,16 +597,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