From 8e2a57b1a63cb1eff2e6faf35dcfe6b0df33be06 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sun, 16 Jun 2024 15:48:51 +0200 Subject: [PATCH 8/9] LibCore: Avoid creating existing directories on Haiku --- Userland/Libraries/LibCore/Directory.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Userland/Libraries/LibCore/Directory.cpp b/Userland/Libraries/LibCore/Directory.cpp index 482ae4ecce..4a17a33b35 100644 --- a/Userland/Libraries/LibCore/Directory.cpp +++ b/Userland/Libraries/LibCore/Directory.cpp @@ -74,6 +74,18 @@ ErrorOr Directory::ensure_directory(LexicalPath const& path, mode_t creati TRY(ensure_directory(path.parent(), creation_mode)); +#ifdef AK_OS_HAIKU + // Haiku throws an error when trying to create a directory that already exists, but is part of the read-only packagefs. + // This can be worked-around by checking if the directory exists first, and then return without recreating it. + auto st_or_error = System::stat(path.string()); + if (!st_or_error.is_error()) + { + auto st = st_or_error.release_value(); + if S_ISDIR(st.st_mode) + return {}; + } +#endif + auto return_value = System::mkdir(path.string(), creation_mode); // We don't care if the directory already exists. if (return_value.is_error() && return_value.error().code() != EEXIST) -- 2.43.2