From b6b2c6f3e2700fec68269f71e612993e5fa6b841 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 15 Sep 2023 21:49:47 +0300 Subject: [PATCH] PackageManager: Create /usr/Ports directory when updating the ports list When updating /usr/Ports/AvailablePorts.md, the file or even the entire /usr/Ports directory might not exist. To cope with this, we should be able to create it ourselves. To ensure we are able to do this, we should unveil both /usr and /usr/Ports. --- Userland/Utilities/pkg/AvailablePort.cpp | 4 ++++ Userland/Utilities/pkg/main.cpp | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Userland/Utilities/pkg/AvailablePort.cpp b/Userland/Utilities/pkg/AvailablePort.cpp index f11829edc9..8e47d6eecb 100644 --- a/Userland/Utilities/pkg/AvailablePort.cpp +++ b/Userland/Utilities/pkg/AvailablePort.cpp @@ -74,6 +74,10 @@ static Optional get_column_in_table(Markdown::Ta ErrorOr AvailablePort::update_available_ports_list_file() { + if (auto error_or_void = Core::System::mkdir("/usr/Ports/"sv, 0655); error_or_void.is_error()) { + if (error_or_void.error().code() != EEXIST) + return error_or_void.release_error(); + } if (!Core::System::access("/usr/Ports/AvailablePorts.md"sv, R_OK).is_error() && FileSystem::remove("/usr/Ports/AvailablePorts.md"sv, FileSystem::RecursionMode::Disallowed).is_error()) { outln("pkg: /usr/Ports/AvailablePorts.md exists, but can't delete it before updating it!"); return 0; diff --git a/Userland/Utilities/pkg/main.cpp b/Userland/Utilities/pkg/main.cpp index c2c11f8853..00b0477c29 100644 --- a/Userland/Utilities/pkg/main.cpp +++ b/Userland/Utilities/pkg/main.cpp @@ -26,8 +26,8 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio recvfd thread unix rpath cpath wpath")); TRY(Core::System::unveil("/tmp/session/%sid/portal/request", "rw")); - TRY(Core::System::unveil("/usr/Ports/installed.db"sv, "rwc"sv)); - TRY(Core::System::unveil("/usr/Ports/AvailablePorts.md"sv, "rwc"sv)); + TRY(Core::System::unveil("/usr"sv, "c"sv)); + TRY(Core::System::unveil("/usr/Ports"sv, "rwc"sv)); TRY(Core::System::unveil("/res"sv, "r"sv)); TRY(Core::System::unveil("/usr/lib"sv, "r"sv)); TRY(Core::System::unveil(nullptr, nullptr)); @@ -54,6 +54,10 @@ ErrorOr serenity_main(Main::Arguments arguments) HashMap installed_ports; HashMap available_ports; if (show_all_installed_ports || show_all_dependency_ports || !query_package.is_null()) { + if (Core::System::access("/usr/Ports/installed.md"sv, R_OK).is_error()) { + warnln("pkg: /usr/Ports/installed.md isn't accessible, did you install a package in the past?"); + return 1; + } installed_ports = TRY(InstalledPort::read_ports_database()); }