Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove share refs from trashbin #2298

Merged
merged 5 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/fix-share-recyclebin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Remove share refs from trashbin

https://github.com/cs3org/reva/pull/2298
8 changes: 6 additions & 2 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eosclient/eosclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("")

Expand All @@ -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}

Expand All @@ -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("")

Expand All @@ -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}

Expand All @@ -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("")

Expand All @@ -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
Expand Down
14 changes: 6 additions & 8 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -1292,19 +1292,17 @@ func (fs *eosfs) deleteShadow(ctx context.Context, p string) error {
}

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, "")
// 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)
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)
Expand Down