vfs: fix rename of directory containing files to be uploaded

Before this change, if you renamed a directory containg files yet to
be uploaded then deleted the directory the files would still be
uploaded.

This fixes the problem by changing the directory path in all the file
objects in a directory when it is renamed. This wasn't necessary until
we introduced virtual files and directories which lived beyond the
directory flush mechanism.

Fixes #6809
This commit is contained in:
Nick Craig-Wood 2023-03-06 11:49:03 +00:00
parent 17854663de
commit 28a8ebce5b
2 changed files with 15 additions and 3 deletions

View File

@ -325,10 +325,15 @@ func (d *Dir) renameTree(dirPath string) {
d.entry = fs.NewDirCopy(context.TODO(), d.entry).SetRemote(dirPath) d.entry = fs.NewDirCopy(context.TODO(), d.entry).SetRemote(dirPath)
} }
// Do the same to any child directories // Do the same to any child directories and files
for leaf, node := range d.items { for leaf, node := range d.items {
if dir, ok := node.(*Dir); ok { switch x := node.(type) {
dir.renameTree(path.Join(dirPath, leaf)) case *Dir:
x.renameTree(path.Join(dirPath, leaf))
case *File:
x.renameDir(dirPath)
default:
panic("bad dir entry")
} }
} }
} }

View File

@ -141,6 +141,13 @@ func (f *File) Node() Node {
return f return f
} }
// renameDir - call when parent directory has been renamed
func (f *File) renameDir(dPath string) {
f.mu.RLock()
f.dPath = dPath
f.mu.RUnlock()
}
// applyPendingRename runs a previously set rename operation if there are no // applyPendingRename runs a previously set rename operation if there are no
// more remaining writers. Call without lock held. // more remaining writers. Call without lock held.
func (f *File) applyPendingRename() { func (f *File) applyPendingRename() {