1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:07:45 +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:
Gurkirat Singh 2023-12-21 16:02:33 +05:30 committed by Tim Schumacher
parent ee639fa1df
commit fc8f6c07b4
7 changed files with 176 additions and 83 deletions

View file

@ -6,14 +6,17 @@
#pragma once
#include "Port.h"
#include <AK/HashMap.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#include <AK/Variant.h>
#include <LibSemVer/SemVer.h>
constexpr StringView ports_database = "/usr/Ports/installed.db"sv;
class InstalledPort {
class InstalledPort : public Port {
public:
enum class Type {
Auto,
@ -24,14 +27,16 @@ public:
static ErrorOr<HashMap<String, InstalledPort>> read_ports_database();
static ErrorOr<void> for_each_by_type(HashMap<String, InstalledPort>&, Type type, Function<ErrorOr<void>(InstalledPort const&)> callback);
InstalledPort(String name, Type type, String version)
: m_name(move(name))
InstalledPort(String const& name, String const& version, Type type)
: Port(name, version)
, m_type(type)
, m_version(move(version))
{
}
Type type() const { return m_type; }
Type type() const
{
return m_type;
}
StringView type_as_string_view() const
{
if (m_type == Type::Auto)
@ -41,13 +46,9 @@ public:
VERIFY_NOT_REACHED();
}
StringView name() const { return m_name.bytes_as_string_view(); }
StringView version() const { return m_version.bytes_as_string_view(); }
ReadonlySpan<String> dependencies() const { return m_dependencies.span(); }
private:
String m_name;
Type m_type;
String m_version;
Vector<String> m_dependencies;
};