Kernel: Support trailing slashes in VFS::mkdir()

This is apparently a special case unlike any other, so let's handle it
directly in VFS::mkdir() instead of adding an alternative code path into
VFS::resolve_path().

Fixes https://github.com/SerenityOS/serenity/issues/1253
This commit is contained in:
Sergey Bugaev 2020-02-20 17:28:36 +03:00 committed by Andreas Kling
parent 7ff256aab6
commit 3439498744

View file

@ -334,6 +334,13 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int optio
KResult VFS::mkdir(StringView path, mode_t mode, Custody& base)
{
// Unlike in basically every other case, where it's only the last
// path component (the one being created) that is allowed not to
// exist, POSIX allows mkdir'ed path to have trailing slashes.
// Let's handle that case by trimming any trailing slashes.
while (path.length() > 1 && path.ends_with("/"))
path = path.substring_view(0, path.length() - 1);
RefPtr<Custody> parent_custody;
auto result = resolve_path(path, base, &parent_custody);
if (!result.is_error())