Check in ListDirSorted that the directory entries all belong
This commit is contained in:
parent
93423a0812
commit
655891170f
1 changed files with 21 additions and 10 deletions
|
@ -618,29 +618,40 @@ func ListDirSorted(fs Fs, includeAll bool, dir string) (entries DirEntries, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter the entries if required
|
// filter the entries if required
|
||||||
if !includeAll {
|
|
||||||
newEntries := entries[:0] // in place filter
|
newEntries := entries[:0] // in place filter
|
||||||
|
prefix := ""
|
||||||
|
if dir != "" {
|
||||||
|
prefix = dir + "/"
|
||||||
|
}
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
|
ok := true
|
||||||
|
if !includeAll {
|
||||||
switch x := entry.(type) {
|
switch x := entry.(type) {
|
||||||
case Object:
|
case Object:
|
||||||
// Make sure we don't delete excluded files if not required
|
// Make sure we don't delete excluded files if not required
|
||||||
if Config.Filter.IncludeObject(x) {
|
if !Config.Filter.IncludeObject(x) {
|
||||||
newEntries = append(newEntries, entry)
|
ok = false
|
||||||
} else {
|
|
||||||
Debugf(x, "Excluded from sync (and deletion)")
|
Debugf(x, "Excluded from sync (and deletion)")
|
||||||
}
|
}
|
||||||
case Directory:
|
case Directory:
|
||||||
if Config.Filter.IncludeDirectory(x.Remote()) {
|
if !Config.Filter.IncludeDirectory(x.Remote()) {
|
||||||
newEntries = append(newEntries, entry)
|
ok = false
|
||||||
} else {
|
|
||||||
Debugf(x, "Excluded from sync (and deletion)")
|
Debugf(x, "Excluded from sync (and deletion)")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nil, errors.Errorf("unknown object type %T", entry)
|
return nil, errors.Errorf("unknown object type %T", entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entries = newEntries
|
remote := entry.Remote()
|
||||||
|
if ok && (!strings.HasPrefix(remote, prefix) || remote == prefix) {
|
||||||
|
ok = false
|
||||||
|
Errorf(entry, "Entry doesn't belong in directory %q - ignoring", dir)
|
||||||
}
|
}
|
||||||
|
if ok {
|
||||||
|
newEntries = append(newEntries, entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entries = newEntries
|
||||||
|
|
||||||
// Sort the directory entries by Remote
|
// Sort the directory entries by Remote
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue