From 3f4f41d4433d102229ec6f4ed2fce2afdb97817e Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:21:18 +0200 Subject: [PATCH 5/7] 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