Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: client/archiver/directory.go

Issue 2980233003: isolate: clean up some path handling (Closed)
Patch Set: fix comment Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/archiver/directory.go
diff --git a/client/archiver/directory.go b/client/archiver/directory.go
index f74c3c85e473306edcfd640bce136ffebfc57812..6a9c36744da4161eee1f07bb99235afeaa562242 100644
--- a/client/archiver/directory.go
+++ b/client/archiver/directory.go
@@ -21,7 +21,6 @@ import (
"log"
"os"
"path/filepath"
- "strings"
"github.com/luci/luci-go/common/isolated"
"github.com/luci/luci-go/common/isolatedclient"
@@ -72,20 +71,23 @@ func walk(root string, blacklist []string, c chan<- *walkItem) {
return
}
}
- if strings.HasSuffix(root, string(filepath.Separator)) {
- root = root[:len(root)-1]
- }
- rootLen := len(root) + 1
err := filepath.Walk(root, func(p string, info os.FileInfo, err error) error {
total++
if err != nil {
return fmt.Errorf("walk(%q): %v", p, err)
}
- if len(p) <= rootLen {
- // Root directory.
- return nil
+
+ relPath, err := filepath.Rel(root, p)
+ if err != nil {
+ return fmt.Errorf("walk: calculating relative path(%q): %v", p, err)
}
- relPath := p[rootLen:]
+
+ // filepath.Rel is documented to call filepath.Clean on its result before returning it,
+ // which results in "." for an empty relative path.
+ if relPath == "." {
+ return nil // Root directory.
+ }
+
for _, b := range blacklist {
matched, _ := filepath.Match(b, relPath)
if !matched {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698