vfs: read directory and check for a file before mkdir
Before this change when doing Mkdir the VFS layer could add the new item to an unread directory which caused confusion. It could also do mkdir on a file when run on a bucket based remote which would temporarily overwrite the file with a directory. Fixes #2993
This commit is contained in:
parent
e3bceb9083
commit
173dfbd051
2 changed files with 44 additions and 2 deletions
|
@ -353,6 +353,33 @@ func TestDirMkdir(t *testing.T) {
|
|||
assert.Equal(t, EROFS, err)
|
||||
}
|
||||
|
||||
func TestDirMkdirSub(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
vfs, dir, file1 := dirCreate(t, r)
|
||||
|
||||
_, err := dir.Mkdir("file1")
|
||||
assert.Error(t, err)
|
||||
|
||||
sub, err := dir.Mkdir("sub")
|
||||
assert.NoError(t, err)
|
||||
|
||||
subsub, err := sub.Mkdir("subsub")
|
||||
assert.NoError(t, err)
|
||||
|
||||
// check the vfs
|
||||
checkListing(t, dir, []string{"file1,14,false", "sub,0,true"})
|
||||
checkListing(t, sub, []string{"subsub,0,true"})
|
||||
checkListing(t, subsub, []string(nil))
|
||||
|
||||
// check the underlying r.Fremote
|
||||
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1}, []string{"dir", "dir/sub", "dir/sub/subsub"}, r.Fremote.Precision())
|
||||
|
||||
vfs.Opt.ReadOnly = true
|
||||
_, err = dir.Mkdir("sausage")
|
||||
assert.Equal(t, EROFS, err)
|
||||
}
|
||||
|
||||
func TestDirRemove(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue