Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
search: use newfind instead and catch errcodes 2/13
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuAlfageme committed Dec 5, 2022
1 parent 26939be commit 40bc30a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ func (c *Client) executeEOS(ctx context.Context, cmdArgs []string, auth eosclien
err = nil
case int(syscall.ENOENT):
err = errtypes.NotFound(errBuf.String())
case int(syscall.EPERM), int(syscall.E2BIG), int(syscall.EINVAL):
case int(syscall.EPERM), int(syscall.E2BIG), int(syscall.EINVAL), int(syscall.EACCES):
// eos reports back error code 1 (EPERM) when ?
// eos reports back error code 7 (E2BIG) when the user is not allowed to read the directory
// eos reports back error code 13 (EACCES) wheb the user is not allowed to read the directory in e.g. eos newfind
// eos reports back error code 22 (EINVAL) when the user is not allowed to enter the instance
err = errtypes.PermissionDenied(errBuf.String())
}
Expand Down Expand Up @@ -746,7 +747,7 @@ func (c *Client) List(ctx context.Context, auth eosclient.Authorization, path st
// List the contents of the directory given by path with depth infinity
func (c *Client) SearchDir(ctx context.Context, auth eosclient.Authorization, searchString string, path string) ([]*eosclient.FileInfo, error) {
// TODO(salfagem): path is truncated - i.e. /c/cernbox (not absolute)
args := []string{"find", "--fileinfo", "-name", searchString, path}
args := []string{"newfind", "--fileinfo", "-name", searchString, path}
log := appctx.GetLogger(ctx)
log.Debug().Msgf("eosbinary search with args: %s", args)
// Safeguard #2 to prevent the search to go to undesired places:
Expand All @@ -763,7 +764,12 @@ func (c *Client) SearchDir(ctx context.Context, auth eosclient.Authorization, se
// TODO: set a timeout for the find in case it goes out of hand
stdout, _, err := c.executeEOS(ctx, args, auth)
if err != nil {
return nil, errors.Wrapf(err, "eosclient: error listing fn=%s", path)
switch err.(type) {
case errtypes.NotFound, errtypes.PermissionDenied:
log.Debug().Msgf("eosbinary - user had insufficient permissions to search part of the directory")
default:
return nil, errors.Wrapf(err, "eosclient: error listing fn=%s", path)
}
}
return c.parseFind(ctx, auth, path, stdout)
}
Expand Down

0 comments on commit 40bc30a

Please sign in to comment.