fix: Block creating files with non-existing parent directories
This commit is contained in:
@@ -93,6 +93,21 @@ func (f *STFS) Create(name string) (afero.File, error) {
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
|
||||
if _, err := inventory.Stat(
|
||||
f.metadata,
|
||||
|
||||
filepath.Dir(name),
|
||||
false,
|
||||
|
||||
f.onHeader,
|
||||
); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, os.ErrNotExist
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return f.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
}
|
||||
|
||||
|
||||
@@ -653,12 +653,11 @@ var createTests = []struct {
|
||||
createArgs{""},
|
||||
true,
|
||||
},
|
||||
// FIXME: STFS can create file in non-existent directory, which should not be possible
|
||||
// {
|
||||
// "Can not create /nonexistent/test.txt",
|
||||
// createArgs{"/nonexistent/test.txt"},
|
||||
// true,
|
||||
// },
|
||||
{
|
||||
"Can not create /nonexistent/test.txt",
|
||||
createArgs{"/nonexistent/test.txt"},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
func TestSTFS_Create(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user