From 8619f2c6f3673aab160dbc2dd1fce877e6583b80 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 19 Dec 2022 18:53:20 +0100 Subject: [PATCH] Kernel+Tests: Remove inaccurate FIXME in sys$rmdir() We were already handling the rmdir("..") case by refusing to remove directories that were not empty. This patch removes a FIXME from January 2019 and adds a test. :^) --- Kernel/FileSystem/VirtualFileSystem.cpp | 2 -- Tests/LibC/TestIo.cpp | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 8dbf04b207..4d0d7dbce0 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -847,8 +847,6 @@ ErrorOr VirtualFileSystem::rmdir(Credentials const& credentials, StringVie if (last_component == "."sv) return EINVAL; - // FIXME: We should return ENOTEMPTY if the last component of the path is ".." - if (!inode.is_directory()) return ENOTDIR; diff --git a/Tests/LibC/TestIo.cpp b/Tests/LibC/TestIo.cpp index 1a0fd2bdcc..5b1bb1b6db 100644 --- a/Tests/LibC/TestIo.cpp +++ b/Tests/LibC/TestIo.cpp @@ -337,6 +337,25 @@ TEST_CASE(rmdir_dot) EXPECT_EQ(rc, 0); } +TEST_CASE(rmdir_dot_dot) +{ + int rc = mkdir("/home/anon/rmdir-test-2", 0700); + EXPECT_EQ(rc, 0); + + rc = mkdir("/home/anon/rmdir-test-2/foo", 0700); + EXPECT_EQ(rc, 0); + + rc = rmdir("/home/anon/rmdir-test-2/foo/.."); + EXPECT_NE(rc, 0); + EXPECT_EQ(errno, ENOTEMPTY); + + rc = rmdir("/home/anon/rmdir-test-2/foo"); + EXPECT_EQ(rc, 0); + + rc = rmdir("/home/anon/rmdir-test-2"); + EXPECT_EQ(rc, 0); +} + TEST_CASE(rmdir_while_inside_dir) { int rc = mkdir("/home/anon/testdir", 0700);