From 4f04d5619e4cbcd88d16ec7ef6d62707086860cd Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte Date: Fri, 19 Nov 2021 16:27:36 +0100 Subject: [PATCH 1/5] Force deletion of a share folder/file without moving it to the recycle bin --- pkg/eosclient/eosbinary/eosbinary.go | 8 ++++++-- pkg/eosclient/eosclient.go | 2 +- pkg/eosclient/eosgrpc/eosgrpc.go | 13 +++++++------ pkg/storage/utils/eosfs/eosfs.go | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pkg/eosclient/eosbinary/eosbinary.go b/pkg/eosclient/eosbinary/eosbinary.go index 6773513962..4fb48fab95 100644 --- a/pkg/eosclient/eosbinary/eosbinary.go +++ b/pkg/eosclient/eosbinary/eosbinary.go @@ -632,8 +632,12 @@ func (c *Client) CreateDir(ctx context.Context, auth eosclient.Authorization, pa } // Remove removes the resource at the given path -func (c *Client) Remove(ctx context.Context, auth eosclient.Authorization, path string) error { - args := []string{"rm", "-r", path} +func (c *Client) Remove(ctx context.Context, auth eosclient.Authorization, path string, noRecycle bool) error { + args := []string{"rm", "-r"} + if noRecycle { + args = append(args, "--no-recycle-bin") // do not put the file in the recycle bin + } + args = append(args, path) _, _, err := c.executeEOS(ctx, args, auth) return err } diff --git a/pkg/eosclient/eosclient.go b/pkg/eosclient/eosclient.go index 30aed21697..c4e47e7b23 100644 --- a/pkg/eosclient/eosclient.go +++ b/pkg/eosclient/eosclient.go @@ -44,7 +44,7 @@ type EOSClient interface { Chown(ctx context.Context, auth, chownauth Authorization, path string) error Chmod(ctx context.Context, auth Authorization, mode, path string) error CreateDir(ctx context.Context, auth Authorization, path string) error - Remove(ctx context.Context, auth Authorization, path string) error + Remove(ctx context.Context, auth Authorization, path string, noRecycle bool) error Rename(ctx context.Context, auth Authorization, oldPath, newPath string) error List(ctx context.Context, auth Authorization, path string) ([]*FileInfo, error) Read(ctx context.Context, auth Authorization, path string) (io.ReadCloser, error) diff --git a/pkg/eosclient/eosgrpc/eosgrpc.go b/pkg/eosclient/eosgrpc/eosgrpc.go index b970c58cfc..1b99010b37 100644 --- a/pkg/eosclient/eosgrpc/eosgrpc.go +++ b/pkg/eosclient/eosgrpc/eosgrpc.go @@ -981,7 +981,7 @@ func (c *Client) CreateDir(ctx context.Context, auth eosclient.Authorization, pa } -func (c *Client) rm(ctx context.Context, auth eosclient.Authorization, path string) error { +func (c *Client) rm(ctx context.Context, auth eosclient.Authorization, path string, noRecycle bool) error { log := appctx.GetLogger(ctx) log.Info().Str("func", "rm").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("") @@ -995,6 +995,7 @@ func (c *Client) rm(ctx context.Context, auth eosclient.Authorization, path stri msg.Id = new(erpc.MDId) msg.Id.Path = []byte(path) + msg.Norecycle = noRecycle rq.Command = &erpc.NSRequest_Unlink{Unlink: msg} @@ -1016,7 +1017,7 @@ func (c *Client) rm(ctx context.Context, auth eosclient.Authorization, path stri } -func (c *Client) rmdir(ctx context.Context, auth eosclient.Authorization, path string) error { +func (c *Client) rmdir(ctx context.Context, auth eosclient.Authorization, path string, noRecycle bool) error { log := appctx.GetLogger(ctx) log.Info().Str("func", "rmdir").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("") @@ -1031,7 +1032,7 @@ func (c *Client) rmdir(ctx context.Context, auth eosclient.Authorization, path s msg.Id = new(erpc.MDId) msg.Id.Path = []byte(path) msg.Recursive = true - msg.Norecycle = false + msg.Norecycle = noRecycle rq.Command = &erpc.NSRequest_Rm{Rm: msg} @@ -1053,7 +1054,7 @@ func (c *Client) rmdir(ctx context.Context, auth eosclient.Authorization, path s } // Remove removes the resource at the given path -func (c *Client) Remove(ctx context.Context, auth eosclient.Authorization, path string) error { +func (c *Client) Remove(ctx context.Context, auth eosclient.Authorization, path string, noRecycle bool) error { log := appctx.GetLogger(ctx) log.Info().Str("func", "Remove").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("") @@ -1064,10 +1065,10 @@ func (c *Client) Remove(ctx context.Context, auth eosclient.Authorization, path } if nfo.IsDir { - return c.rmdir(ctx, auth, path) + return c.rmdir(ctx, auth, path, noRecycle) } - return c.rm(ctx, auth, path) + return c.rm(ctx, auth, path, noRecycle) } // Rename renames the resource referenced by oldPath to newPath diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 29259ecd0c..f01217023b 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -1283,7 +1283,7 @@ func (fs *eosfs) Delete(ctx context.Context, ref *provider.Reference) error { return err } - return fs.c.Remove(ctx, auth, fn) + return fs.c.Remove(ctx, auth, fn, false) } func (fs *eosfs) deleteShadow(ctx context.Context, p string) error { @@ -1304,7 +1304,7 @@ func (fs *eosfs) deleteShadow(ctx context.Context, p string) error { return err } - return fs.c.Remove(ctx, auth, fn) + return fs.c.Remove(ctx, auth, fn, true) } return errors.New("eosfs: shadow delete of share folder that is neither root nor child. path=" + p) From 6a497881471f3bcf3af0a898888ff36d9a059620 Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte Date: Fri, 19 Nov 2021 17:00:52 +0100 Subject: [PATCH 2/5] Use root auth to not use the recycle bin --- pkg/storage/utils/eosfs/eosfs.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index f01217023b..7c6671e03e 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -1286,23 +1286,27 @@ func (fs *eosfs) Delete(ctx context.Context, ref *provider.Reference) error { return fs.c.Remove(ctx, auth, fn, false) } +func getRootAuth() eosclient.Authorization { + return eosclient.Authorization{ + Role: eosclient.Role{ + UID: "0", + GID: "0", + }, + } +} + func (fs *eosfs) deleteShadow(ctx context.Context, p string) error { if fs.isShareFolderRoot(ctx, p) { return errtypes.PermissionDenied("eosfs: cannot delete the virtual share folder") } if fs.isShareFolderChild(ctx, p) { - u, err := getUser(ctx) - if err != nil { - return errors.Wrap(err, "eosfs: no user in ctx") - } - fn := fs.wrapShadow(ctx, p) - - auth, err := fs.getUserAuth(ctx, u, "") - if err != nil { - return err - } + + // in order to remove definitely the folder or the file + // without moving it to the recycle bin, we should take + // the priviledges of the root + auth := getRootAuth() return fs.c.Remove(ctx, auth, fn, true) } From 38dcc5d03a4eb1c641955751be56a530fc9f5c04 Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte Date: Fri, 19 Nov 2021 17:14:25 +0100 Subject: [PATCH 3/5] Add changelog --- changelog/unreleased/fix-share-recyclebin.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/unreleased/fix-share-recyclebin.md diff --git a/changelog/unreleased/fix-share-recyclebin.md b/changelog/unreleased/fix-share-recyclebin.md new file mode 100644 index 0000000000..fb0b500138 --- /dev/null +++ b/changelog/unreleased/fix-share-recyclebin.md @@ -0,0 +1,3 @@ +Bugfix: Remove share refs from trashbin + +https://github.com/cs3org/reva/pull/2298 \ No newline at end of file From 92a58284fa90ff52d712aa46cf935e70c9aa8115 Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte Date: Mon, 22 Nov 2021 09:51:40 +0100 Subject: [PATCH 4/5] Fix linting --- pkg/eosclient/eosbinary/eosbinary.go | 2 +- pkg/storage/utils/eosfs/eosfs.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/eosclient/eosbinary/eosbinary.go b/pkg/eosclient/eosbinary/eosbinary.go index 4fb48fab95..b9c1f6a5a4 100644 --- a/pkg/eosclient/eosbinary/eosbinary.go +++ b/pkg/eosclient/eosbinary/eosbinary.go @@ -637,7 +637,7 @@ func (c *Client) Remove(ctx context.Context, auth eosclient.Authorization, path if noRecycle { args = append(args, "--no-recycle-bin") // do not put the file in the recycle bin } - args = append(args, path) + args = append(args, path) _, _, err := c.executeEOS(ctx, args, auth) return err } diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 7c6671e03e..9873643676 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -1288,11 +1288,11 @@ func (fs *eosfs) Delete(ctx context.Context, ref *provider.Reference) error { func getRootAuth() eosclient.Authorization { return eosclient.Authorization{ - Role: eosclient.Role{ - UID: "0", - GID: "0", - }, - } + Role: eosclient.Role{ + UID: "0", + GID: "0", + }, + } } func (fs *eosfs) deleteShadow(ctx context.Context, p string) error { @@ -1302,7 +1302,7 @@ func (fs *eosfs) deleteShadow(ctx context.Context, p string) error { if fs.isShareFolderChild(ctx, p) { fn := fs.wrapShadow(ctx, p) - + // in order to remove definitely the folder or the file // without moving it to the recycle bin, we should take // the priviledges of the root From 2bb3e23c805828cd1227dca38c3098c44147e832 Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte Date: Mon, 29 Nov 2021 11:46:16 +0100 Subject: [PATCH 5/5] Changes for review --- pkg/storage/utils/eosfs/eosfs.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 9873643676..ca12042d3d 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -1286,15 +1286,6 @@ func (fs *eosfs) Delete(ctx context.Context, ref *provider.Reference) error { return fs.c.Remove(ctx, auth, fn, false) } -func getRootAuth() eosclient.Authorization { - return eosclient.Authorization{ - Role: eosclient.Role{ - UID: "0", - GID: "0", - }, - } -} - func (fs *eosfs) deleteShadow(ctx context.Context, p string) error { if fs.isShareFolderRoot(ctx, p) { return errtypes.PermissionDenied("eosfs: cannot delete the virtual share folder") @@ -1303,10 +1294,13 @@ func (fs *eosfs) deleteShadow(ctx context.Context, p string) error { if fs.isShareFolderChild(ctx, p) { fn := fs.wrapShadow(ctx, p) - // in order to remove definitely the folder or the file - // without moving it to the recycle bin, we should take - // the priviledges of the root - auth := getRootAuth() + // in order to remove the folder or the file without + // moving it to the recycle bin, we should take + // the privileges of the root + auth, err := fs.getRootAuth(ctx) + if err != nil { + return err + } return fs.c.Remove(ctx, auth, fn, true) }