#pragma once #include "package-manager.h" #include #include // Native Arch Linux package manager, integrated directly into the application class PacmanManager : public IPackageManager { public: std::string getName() const override { return "pacman"; } std::string getVersion() const override { return "1.0.0"; } std::string getDescription() const override { return "Gestionnaire de paquets natif d'Arch Linux"; } bool canSearch() const override { return true; } bool canInstall() const override { return true; } bool canRemove() const override { return true; } bool canUpdate() const override { return true; } bool canListInstalled() const override { return true; } bool isAvailable() const override { return system("which pacman > /dev/null 2>&1") == 0; } // pacman operations run through sudo and need the session password. bool requiresPassword() const override { return true; } // Parse `pacman -Q` output (one "name version" line per package). // Exposed as static so the parsing can be unit-tested without invoking pacman. static std::vector parseInstalledOutput(const std::string& output); // Parse `pacman -Q` output into a set of installed package names, used to // mark search results as installed without one subprocess per result. // Exposed as static so the parsing can be unit-tested without invoking pacman. static std::set parseInstalledNames(const std::string& output); // Parse `pacman -Qi` output (one block per package) into a name -> installed size map. // Exposed as static so the parsing can be unit-tested without invoking pacman. static std::map parseInstalledSizes(const std::string& output); // Parse `pacman -Sl` output ("repo name version" per line) into a name -> repository map. // Exposed as static so the parsing can be unit-tested without invoking pacman. static std::map parseSyncRepos(const std::string& output); // Detect a sudo authentication failure (wrong or missing password) in the // output of a privileged command. Exposed as static so it can be // unit-tested without invoking sudo. static bool authFailed(const std::string& output); // Detect a locked pacman database (db.lck) in the output, either because // another manager runs concurrently or because a stale lock file remains. // Exposed as static so it can be unit-tested without invoking pacman. static bool dbLocked(const std::string& output); // User-facing hint explaining the lock and how to recover. Checks the // lock file and other running managers on the live system. static std::string dbLockHint(); // Last error detail of the most recent failed privileged operation // (e.g. db lock hint), surfaced in the UI instead of a generic message. std::string lastError() const override { return m_lastError; } // Credential handling for privileged (sudo) operations. The password is // kept in memory only for the session (never persisted) and piped to // `sudo -S` for each privileged command. void setPassword(const std::string& password); void clearPassword(); bool hasPassword() const; std::vector search(const std::string& query) override; bool install(const std::string& packageName, ProgressCallback progressCallback) override; bool remove(const std::string& packageName, ProgressCallback progressCallback) override; bool update(const std::string& packageName = "", ProgressCallback progressCallback = nullptr) override; std::vector listInstalled() override; std::vector listUpdates() override; bool refresh(ProgressCallback progressCallback = nullptr) override; private: bool isPackageInstalled(const std::string& name); std::string m_password; std::string m_lastError; };