mirror of https://github.com/rclone/rclone
vfs: fix renaming a directory
Before this change, renaming a directory d failed to rename its key in d.parent.items, which caused trouble later when doing Dir.Stat on a subdirectory. This change fixes the issue.
This commit is contained in:
parent
527cec4337
commit
15ff8ab01e
13
vfs/dir.go
13
vfs/dir.go
|
@ -371,7 +371,9 @@ func (d *Dir) renameTree(dirPath string) {
|
|||
// Make sure the path is correct for each node
|
||||
if d.path != dirPath {
|
||||
fs.Debugf(d.path, "Renaming to %q", dirPath)
|
||||
delete(d.parent.items, name(d.path))
|
||||
d.path = dirPath
|
||||
d.parent.items[name(d.path)] = d
|
||||
d.entry = fs.NewDirCopy(context.TODO(), d.entry).SetRemote(dirPath)
|
||||
}
|
||||
|
||||
|
@ -404,6 +406,8 @@ func (d *Dir) rename(newParent *Dir, fsDir fs.Directory) {
|
|||
d.entry = fsDir
|
||||
d.path = fsDir.Remote()
|
||||
newPath := d.path
|
||||
delete(d.parent.items, name(oldPath))
|
||||
d.parent.items[name(d.path)] = d
|
||||
d.read = time.Time{}
|
||||
d.mu.Unlock()
|
||||
|
||||
|
@ -418,6 +422,15 @@ func (d *Dir) rename(newParent *Dir, fsDir fs.Directory) {
|
|||
}
|
||||
}
|
||||
|
||||
// convert path to name
|
||||
func name(p string) string {
|
||||
p = path.Base(p)
|
||||
if p == "." {
|
||||
p = "/"
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// addObject adds a new object or directory to the directory
|
||||
//
|
||||
// The name passed in is marked as virtual as it hasn't been read from a remote
|
||||
|
|
Loading…
Reference in New Issue