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:
+17
-2
@@ -458,8 +458,23 @@ func (d *Dir) Mkdir(name string) (*Dir, error) {
|
||||
return nil, EROFS
|
||||
}
|
||||
path := path.Join(d.path, name)
|
||||
node, err := d.stat(name)
|
||||
switch err {
|
||||
case ENOENT:
|
||||
// not found, carry on
|
||||
case nil:
|
||||
// found so check what it is
|
||||
if node.IsDir() {
|
||||
return node.(*Dir), err
|
||||
}
|
||||
return nil, EEXIST
|
||||
default:
|
||||
// a different error - report
|
||||
fs.Errorf(d, "Dir.Mkdir failed to read directory: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
// fs.Debugf(path, "Dir.Mkdir")
|
||||
err := d.f.Mkdir(path)
|
||||
err = d.f.Mkdir(path)
|
||||
if err != nil {
|
||||
fs.Errorf(d, "Dir.Mkdir failed to create directory: %v", err)
|
||||
return nil, err
|
||||
@@ -600,7 +615,7 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
|
||||
}
|
||||
default:
|
||||
err = errors.Errorf("unknown type %T", oldNode)
|
||||
fs.Errorf(d.path, "Dir.ReadDirAll error: %v", err)
|
||||
fs.Errorf(d.path, "Dir.Rename error: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user