mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
VirtualFileSystem: Don't let rename() overwrite non-empty directory
According to POSIX, rename shouldn't succeed if newpath is a non-empty directory.
This commit is contained in:
parent
f16011e4d1
commit
3dd40535c1
1 changed files with 16 additions and 0 deletions
|
@ -499,6 +499,22 @@ KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Cust
|
||||||
return EPERM;
|
return EPERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!new_custody_or_error.is_error()) {
|
||||||
|
auto& new_inode = new_custody_or_error.value()->inode();
|
||||||
|
|
||||||
|
if (old_inode.index() != new_inode.index() && old_inode.is_directory() && new_inode.is_directory()) {
|
||||||
|
size_t child_count = 0;
|
||||||
|
auto traversal_result = new_inode.traverse_as_directory([&child_count](auto&) {
|
||||||
|
++child_count;
|
||||||
|
return child_count <= 2;
|
||||||
|
});
|
||||||
|
if (traversal_result.is_error())
|
||||||
|
return traversal_result;
|
||||||
|
if (child_count > 2)
|
||||||
|
return ENOTEMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto& old_parent_inode = old_parent_custody->inode();
|
auto& old_parent_inode = old_parent_custody->inode();
|
||||||
auto& new_parent_inode = new_parent_custody->inode();
|
auto& new_parent_inode = new_parent_custody->inode();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue