mirror of
https://github.com/rclone/rclone.git
synced 2024-11-26 10:25:03 +01:00
fs: Add Find method to DirTree
This commit is contained in:
parent
d5ff7104e5
commit
71fe046937
22
fs/walk.go
22
fs/walk.go
@ -203,19 +203,27 @@ func (dt DirTree) addDir(entry DirEntry) {
|
||||
}
|
||||
}
|
||||
|
||||
// Find returns the DirEntry for filePath or nil if not found
|
||||
func (dt DirTree) Find(filePath string) (parentPath string, entry DirEntry) {
|
||||
parentPath = parentDir(filePath)
|
||||
for _, entry := range dt[parentPath] {
|
||||
if entry.Remote() == filePath {
|
||||
return parentPath, entry
|
||||
}
|
||||
}
|
||||
return parentPath, nil
|
||||
}
|
||||
|
||||
// check that dirPath has a *Dir in its parent
|
||||
func (dt DirTree) checkParent(root, dirPath string) {
|
||||
if dirPath == root {
|
||||
return
|
||||
}
|
||||
parentPath := parentDir(dirPath)
|
||||
entries := dt[parentPath]
|
||||
for _, entry := range entries {
|
||||
if entry.Remote() == dirPath {
|
||||
return
|
||||
}
|
||||
parentPath, entry := dt.Find(dirPath)
|
||||
if entry != nil {
|
||||
return
|
||||
}
|
||||
dt[parentPath] = append(entries, NewDir(dirPath, time.Now()))
|
||||
dt[parentPath] = append(dt[parentPath], NewDir(dirPath, time.Now()))
|
||||
dt.checkParent(root, parentPath)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user