Skip to content

Commit

Permalink
Allow partially valid results returned from find command when listi…
Browse files Browse the repository at this point in the history
…ng files and directories (#2311)

* Minor fix for the temporary directory for on-disk cache

If and only if the $TMPDIR env is not set should we try to fallback to
/tmp as the temporary directory for on-disk cache files.

* Do not return nil if `find` returns error when listing dir/files on remote ssh device

`find` command may partially succeed, in which case we should process
the successfully listed items and ignore the error messages. This CL
redirect the errors generated by `find` to /dev/null to strip away error
messages.
  • Loading branch information
Qining authored Oct 22, 2018
1 parent e0dd5d9 commit ab5e031
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions core/os/device/remotessh/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,9 @@ func (b binding) ListExecutables(ctx context.Context, inPath string) ([]string,
if inPath == "" {
inPath = b.GetURIRoot()
}
files, err := b.Shell("find", `"`+inPath+`"`, "-mindepth", "1", "-maxdepth", "1", "-type", "f", "-executable", "-printf", `%f\\n`).Call(ctx)
if err != nil {
return nil, err
}
// 'find' may partially succeed. Redirect the error messages to /dev/null,
// only process the successfully found executables.
files, _ := b.Shell("find", `"`+inPath+`"`, "-mindepth", "1", "-maxdepth", "1", "-type", "f", "-executable", "-printf", `%f\\n`, "2>/dev/null").Call(ctx)
scanner := bufio.NewScanner(strings.NewReader(files))
out := []string{}
for scanner.Scan() {
Expand All @@ -339,10 +338,9 @@ func (b binding) ListDirectories(ctx context.Context, inPath string) ([]string,
if inPath == "" {
inPath = b.GetURIRoot()
}
dirs, err := b.Shell("find", `"`+inPath+`"`, "-mindepth", "1", "-maxdepth", "1", "-type", "d", "-printf", `%f\\n`).Call(ctx)
if err != nil {
return nil, err
}
// 'find' may partially succeed. Redirect the error messages to /dev/null,
// only process the successfully found directories.
dirs, _ := b.Shell("find", `"`+inPath+`"`, "-mindepth", "1", "-maxdepth", "1", "-type", "d", "-printf", `%f\\n`, "2>/dev/null").Call(ctx)
scanner := bufio.NewScanner(strings.NewReader(dirs))
out := []string{}
for scanner.Scan() {
Expand Down

0 comments on commit ab5e031

Please sign in to comment.