vfs: fix virtual entries causing deleted files to still appear
Before this change, if a file was created on a remote but deleted externally from that remote then there was potential for the delete to never be noticed. The sequence of events was: - Create file on VFS - creates virtual directory entry - File deleted externally to remote before the directory refreshed - Now the file has a virtual add but is not in the listings so will never disappear This patch fixes it by removing all virtual directory entries except the following when the directory is re-read. - On remotes which can't have empty directories: virtual directory adds are not flushed. These will remain virtual as long as the directory is empty. - For virtual file add: files that are in the process of being uploaded are not flushed This patch also adds the distinction between virtually added files and directories. It also refactors the virtual directory logic to make it easier to follow. Fixes #4446
This commit is contained in:
parent
e204f89685
commit
f980f230c5
4 changed files with 184 additions and 54 deletions
|
@ -289,16 +289,6 @@ func TestDirReadDirAll(t *testing.T) {
|
|||
|
||||
checkListing(t, dir, []string{"file1,14,false", "virtualDir,0,true", "virtualFile,17,false"})
|
||||
|
||||
// Force a directory reload...
|
||||
dir.invalidateDir("dir")
|
||||
|
||||
checkListing(t, dir, []string{"file1,14,false", "virtualDir,0,true", "virtualFile,17,false"})
|
||||
|
||||
// Check that forgetting the root doesn't invalidate the virtual entries
|
||||
root.ForgetAll()
|
||||
|
||||
checkListing(t, dir, []string{"file1,14,false", "virtualDir,0,true", "virtualFile,17,false"})
|
||||
|
||||
// Now action the deletes and uploads
|
||||
_ = r.WriteObject(context.Background(), "dir/virtualFile", "virtualFile contents", t1)
|
||||
_ = r.WriteObject(context.Background(), "dir/virtualDir/testFile", "testFile contents", t1)
|
||||
|
@ -317,6 +307,29 @@ func TestDirReadDirAll(t *testing.T) {
|
|||
assert.Nil(t, dir.virtual)
|
||||
dir.mu.Unlock()
|
||||
|
||||
// Add some virtual entries and check what happens
|
||||
dir.AddVirtual("virtualFile2", 100, false)
|
||||
dir.AddVirtual("virtualDir2", 0, true)
|
||||
// Remove some existing entries
|
||||
dir.DelVirtual("file1")
|
||||
|
||||
checkListing(t, dir, []string{"virtualDir,0,true", "virtualDir2,0,true", "virtualFile,20,false", "virtualFile2,100,false"})
|
||||
|
||||
// Force a directory reload...
|
||||
dir.invalidateDir("dir")
|
||||
|
||||
want := []string{"file1,14,false", "virtualDir,0,true", "virtualDir2,0,true", "virtualFile,20,false", "virtualFile2,100,false"}
|
||||
features := r.Fremote.Features()
|
||||
if features.CanHaveEmptyDirectories {
|
||||
// snip out virtualDir2 which will only be present if can't have empty dirs
|
||||
want = append(want[:2], want[3:]...)
|
||||
}
|
||||
checkListing(t, dir, want)
|
||||
|
||||
// Check that forgetting the root doesn't invalidate the virtual entries
|
||||
root.ForgetAll()
|
||||
|
||||
checkListing(t, dir, want)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue