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.
This commit is contained in:
parent
4303965986
commit
b6b2c6f3e2
Notes:
sideshowbarker
2024-07-17 01:11:48 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/b6b2c6f3e2 Pull-request: https://github.com/SerenityOS/serenity/pull/21099 Issue: https://github.com/SerenityOS/serenity/issues/21015
2 changed files with 10 additions and 2 deletions
|
@ -74,6 +74,10 @@ static Optional<Markdown::Table::Column const&> get_column_in_table(Markdown::Ta
|
|||
|
||||
ErrorOr<int> 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;
|
||||
|
|
|
@ -26,8 +26,8 @@ ErrorOr<int> 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<int> serenity_main(Main::Arguments arguments)
|
|||
HashMap<String, InstalledPort> installed_ports;
|
||||
HashMap<String, AvailablePort> 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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue