From 3439498744028f6f38a172f119949d69d70cde19 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Thu, 20 Feb 2020 17:28:36 +0300 Subject: [PATCH] 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 --- Kernel/FileSystem/VirtualFileSystem.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index d34fa74830..8405be4ce3 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -334,6 +334,13 @@ KResultOr> 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 parent_custody; auto result = resolve_path(path, base, &parent_custody); if (!result.is_error())