Skip to content

Commit 447aefd

Browse files
committed
Fix when target dir is root ('/')
1 parent 843b474 commit 447aefd

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

fs.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ func (fs *CachedFS) Fill() (int, error) {
127127

128128
cnt := 0
129129
dirs := []int64{0}
130+
root := fs.Root
130131
trim := len(fs.Root)
132+
133+
if strings.HasSuffix(root, string(filepath.Separator)) {
134+
trim--
135+
} else {
136+
root += string(filepath.Separator)
137+
}
138+
131139
err = walk.Walk(fs.Root, &walk.Options{
132140
Error: func(r string, e *walk.Dirent, err error) error {
133141
logErr.Printf("Error iterating \"%s\": %s\n", r, err.Error())
@@ -184,13 +192,18 @@ func (fs *CachedFS) Fill() (int, error) {
184192
if err != nil {
185193
return err
186194
}
187-
if strings.HasPrefix(a, fs.Root) {
195+
if strings.HasPrefix(a, root) {
188196
logErr.Printf("Skipping symlink relative to root (%s)\n", r)
189197
return filepath.SkipDir
190198
}
191199
}
192200

193-
row, err := idir.Exec(r[trim:] + "/")
201+
dir := filepath.ToSlash(r[trim:])
202+
if dir != "/" {
203+
dir += "/"
204+
}
205+
206+
row, err := idir.Exec(dir)
194207
if err != nil {
195208
return err
196209
}

0 commit comments

Comments
 (0)