fix: Prevent creating directories with no parent
This commit is contained in:
@@ -283,6 +283,21 @@ func (f *STFS) Mkdir(name string, perm os.FileMode) error {
|
||||
f.ioLock.Lock()
|
||||
defer f.ioLock.Unlock()
|
||||
|
||||
if _, err := inventory.Stat(
|
||||
f.metadata,
|
||||
|
||||
filepath.Dir(name),
|
||||
false,
|
||||
|
||||
f.onHeader,
|
||||
); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return os.ErrNotExist
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
if hdr, err := inventory.Stat(
|
||||
f.metadata,
|
||||
|
||||
|
||||
@@ -806,13 +806,13 @@ var mkdirTests = []struct {
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"Can create directory /test.txt",
|
||||
mkdirArgs{"/test.txt", os.ModePerm},
|
||||
"Can create directory /test",
|
||||
mkdirArgs{"/test", os.ModePerm},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"Can create directory /test.txt with different permissions",
|
||||
mkdirArgs{"/test.txt", 0666},
|
||||
"Can create directory /test with different permissions",
|
||||
mkdirArgs{"/test", 0666},
|
||||
false,
|
||||
},
|
||||
{
|
||||
@@ -830,12 +830,11 @@ var mkdirTests = []struct {
|
||||
mkdirArgs{"", os.ModePerm},
|
||||
true,
|
||||
},
|
||||
// FIXME: STFS can create directory in non-existent directory, which should not be possible
|
||||
// {
|
||||
// "Can not create /nonexistent/test.txt",
|
||||
// mkdirArgs{"/nonexistent/test.txt", os.ModePerm},
|
||||
// true,
|
||||
// },
|
||||
{
|
||||
"Can not create /nonexistent/test",
|
||||
mkdirArgs{"/nonexistent/test", os.ModePerm},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
func TestSTFS_Mkdir(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user