mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
Utilities/pkg: Integrate LibSemVer for update information
Along with this, Port.h is include which helps generalising common information for the port package, like it's name and version. With SemVer complaint versions, it is possible to show positive change (upgrade) or negative change (downgrade) in the installed ports. However, for some non-complaint versions (eg. using git commit hash), non-equality (`!=`) is used to notify upgrade. Since there is no algorithm (without git history) to check the order of commits, it is not possible to inform whether it is an upgrade or downgrade.
This commit is contained in:
parent
ee639fa1df
commit
fc8f6c07b4
7 changed files with 176 additions and 83 deletions
|
@ -11,9 +11,30 @@
|
|||
#include <LibMain/Main.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void print_port_details(InstalledPort const& port)
|
||||
static void print_port_details(InstalledPort const& port, Optional<AvailablePort> const& available_port)
|
||||
{
|
||||
outln("{}, installed as {}, version {}", port.name(), port.type_as_string_view(), port.version());
|
||||
out("{}, installed as {}, version {}", port.name(), port.type_as_string_view(), port.version_string());
|
||||
if (available_port.has_value()) {
|
||||
auto const& upstream_port = available_port.value();
|
||||
auto const& upstream_version = upstream_port.version_semver();
|
||||
auto const& this_version = port.version_semver();
|
||||
|
||||
if ((this_version.is_error() || upstream_version.is_error())) {
|
||||
if (upstream_port.version_string() != port.version_string()) {
|
||||
outln(" (upgrade available -> {})", upstream_port.version_string());
|
||||
}
|
||||
} else {
|
||||
auto const& ap_version = upstream_version.value();
|
||||
auto const& ip_version = this_version.value();
|
||||
if (ip_version.is_same(ap_version)) {
|
||||
outln(" (already on latest version)");
|
||||
} else if (ip_version.is_lesser_than(ap_version)) {
|
||||
outln(" (upgrade available {})", ap_version.to_string());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
outln();
|
||||
}
|
||||
|
||||
if (!port.dependencies().is_empty()) {
|
||||
out(" Dependencies:");
|
||||
|
@ -51,16 +72,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return 0;
|
||||
}
|
||||
|
||||
HashMap<String, InstalledPort> installed_ports;
|
||||
HashMap<String, AvailablePort> available_ports;
|
||||
if (show_all_installed_ports || !query_package.is_null()) {
|
||||
if (Core::System::access(ports_database, R_OK).is_error()) {
|
||||
warnln("pkg: {} isn't accessible, did you install a package in the past?", ports_database);
|
||||
return 1;
|
||||
}
|
||||
installed_ports = TRY(InstalledPort::read_ports_database());
|
||||
}
|
||||
|
||||
int return_value = 0;
|
||||
if (update_packages_db) {
|
||||
if (getuid() != 0) {
|
||||
|
@ -70,18 +81,27 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return_value = TRY(AvailablePort::update_available_ports_list_file());
|
||||
}
|
||||
|
||||
if (!query_package.is_null()) {
|
||||
if (Core::System::access("/usr/Ports/AvailablePorts.md"sv, R_OK).is_error()) {
|
||||
outln("pkg: Please run this program with -u first!");
|
||||
return 0;
|
||||
}
|
||||
available_ports = TRY(AvailablePort::read_available_ports_list());
|
||||
if (Core::System::access(ports_database, R_OK).is_error()) {
|
||||
warnln("pkg: {} isn't accessible, did you install a package in the past?", ports_database);
|
||||
return 1;
|
||||
}
|
||||
HashMap<String, InstalledPort> installed_ports = TRY(InstalledPort::read_ports_database());
|
||||
|
||||
if (Core::System::access("/usr/Ports/AvailablePorts.md"sv, R_OK).is_error()) {
|
||||
outln("pkg: Please run this program with -u first!");
|
||||
return 0;
|
||||
}
|
||||
HashMap<String, AvailablePort> available_ports = TRY(AvailablePort::read_available_ports_list());
|
||||
|
||||
if (show_all_installed_ports) {
|
||||
outln("Manually-installed ports:");
|
||||
TRY(InstalledPort::for_each_by_type(installed_ports, InstalledPort::Type::Manual, [](auto& port) -> ErrorOr<void> {
|
||||
print_port_details(port);
|
||||
TRY(InstalledPort::for_each_by_type(installed_ports, InstalledPort::Type::Manual, [available_ports](InstalledPort const& port) -> ErrorOr<void> {
|
||||
auto available_port = available_ports.find(port.name());
|
||||
if (available_port != available_ports.end()) {
|
||||
print_port_details(port, available_port->value);
|
||||
} else {
|
||||
print_port_details(port, {});
|
||||
}
|
||||
return {};
|
||||
}));
|
||||
}
|
||||
|
@ -91,7 +111,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
outln("pkg: Queried package name is empty.");
|
||||
return 0;
|
||||
}
|
||||
return_value = TRY(AvailablePort::query_details_for_package(available_ports, installed_ports, query_package, verbose));
|
||||
AvailablePort::query_details_for_package(available_ports, installed_ports, query_package, verbose);
|
||||
}
|
||||
|
||||
return return_value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue