From 28a8ebce5b5df05d73b485d74d42fb9097ee789d Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 6 Mar 2023 11:49:03 +0000 Subject: [PATCH] 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 --- vfs/dir.go | 11 ++++++++--- vfs/file.go | 7 +++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/vfs/dir.go b/vfs/dir.go index c45033d0e..2087dc638 100644 --- a/vfs/dir.go +++ b/vfs/dir.go @@ -325,10 +325,15 @@ func (d *Dir) renameTree(dirPath string) { 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 { - if dir, ok := node.(*Dir); ok { - dir.renameTree(path.Join(dirPath, leaf)) + switch x := node.(type) { + case *Dir: + x.renameTree(path.Join(dirPath, leaf)) + case *File: + x.renameDir(dirPath) + default: + panic("bad dir entry") } } } diff --git a/vfs/file.go b/vfs/file.go index 5e5c74f97..44a4ebb88 100644 --- a/vfs/file.go +++ b/vfs/file.go @@ -141,6 +141,13 @@ func (f *File) Node() Node { 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 // more remaining writers. Call without lock held. func (f *File) applyPendingRename() {