223 lines
6.2 KiB
C++
223 lines
6.2 KiB
C++
#ifndef ALPM_MANAGER_H
|
|
#define ALPM_MANAGER_H
|
|
|
|
#include "./upgradelookup.h"
|
|
#include "./alpmpackage.h"
|
|
|
|
#include <alpm.h>
|
|
|
|
#include <QNetworkAccessManager>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
#include <QMutex>
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
|
|
namespace RepoIndex {
|
|
|
|
class Config;
|
|
class UserRepository;
|
|
class AlpmDatabase;
|
|
|
|
class Manager
|
|
{
|
|
public:
|
|
enum PackageInfoPart {
|
|
None = 0x0,
|
|
Basics = 0x1,
|
|
Details = 0x2,
|
|
};
|
|
Q_DECLARE_FLAGS(PackageInfoParts, PackageInfoPart)
|
|
|
|
explicit Manager(const Config &config);
|
|
Manager(const Manager &other) = delete;
|
|
Manager(Manager &&other) = delete;
|
|
Manager &operator =(const Manager &other) = delete;
|
|
~Manager();
|
|
|
|
// configuration, signature level, etc
|
|
const Config &config() const;
|
|
bool writeCacheBeforeGone() const;
|
|
void setWriteCacheBeforeGone(bool writeCacheBeforeGone);
|
|
int sigLevel() const;
|
|
void setSigLevel(int sigLevel);
|
|
int localFileSigLevel() const;
|
|
void setLocalFileSigLevel(int sigLevel);
|
|
const QString &pacmanCacheDir() const;
|
|
static int parseSigLevel(const std::string &sigLevelStr = std::string());
|
|
static int parseUsage(const std::string &usageStr);
|
|
void initAlpmHandle();
|
|
void cleanupAlpm();
|
|
void registerDataBasesFromPacmanConfig();
|
|
void registerDatabasesFromRepoIndexConfig();
|
|
void initAlpmDataBases(bool computeRequiredBy);
|
|
void writeCache();
|
|
void restoreCache();
|
|
|
|
void unregisterSyncDataBases();
|
|
|
|
// package lookup
|
|
AlpmPackage *packageFromDatabase(const QString &dbName, const QString &pkgName);
|
|
const AlpmPackage *packageFromDatabase(const QString &dbName, const QString &pkgName) const;
|
|
AlpmPackage *packageFromSyncDatabases(const QString &pkgName);
|
|
const AlpmPackage *packageFromSyncDatabases(const QString &pkgName) const;
|
|
std::unique_ptr<AlpmOwnershipPackage> packageFromFile(const char *fileName, bool verifyIntegrity = false);
|
|
Package *packageProviding(const Dependency &dependency);
|
|
const Package *packageProviding(const Dependency &dependency) const;
|
|
bool isPackageIgnored(const AlpmPackage *package) const;
|
|
void setInstallReason(AlpmPackage *package, alpm_pkgreason_t reason);
|
|
|
|
// repository lookup
|
|
const AlpmDatabase *localDataBase() const;
|
|
AlpmDatabase *localDataBase();
|
|
const std::map<QString, std::unique_ptr<AlpmDatabase> > &syncDatabases() const;
|
|
const AlpmDatabase *databaseByName(const QString &dbName) const;
|
|
AlpmDatabase *databaseByName(const QString &dbName);
|
|
const Repository *repositoryByName(const QString &name) const;
|
|
Repository *repositoryByName(const QString &name);
|
|
const UserRepository *userRepository() const;
|
|
UserRepository *userRepository();
|
|
const UpgradeLookupResults checkForUpgrades(AlpmDatabase *db) const;
|
|
|
|
// JSON serialization, handling JSON requests
|
|
const QJsonObject basicRepoInfo(const Repository *packageSource) const;
|
|
const QJsonObject &basicRepoInfo() const;
|
|
const QJsonArray packageInfo(const QJsonObject &pkgSelection, PackageInfoPart part) const;
|
|
const QJsonArray &groupInfo() const;
|
|
|
|
private:
|
|
const Config &m_config;
|
|
bool m_writeCacheBeforeGone;
|
|
alpm_handle_t *m_handle;
|
|
int m_sigLevel;
|
|
int m_localFileSigLevel;
|
|
QString m_pacmanCacheDir;
|
|
QNetworkAccessManager m_networkAccessManager;
|
|
std::unique_ptr<UserRepository> m_userRepo;
|
|
std::unique_ptr<AlpmDatabase> m_localDb;
|
|
std::map<QString, std::unique_ptr<AlpmDatabase> > m_syncDbs;
|
|
mutable QJsonObject m_basicRepoInfo;
|
|
mutable QMutex m_basicRepoInfoMutex;
|
|
mutable QJsonArray m_groupInfo;
|
|
mutable QMutex m_groupInfoMutex;
|
|
};
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Manager::PackageInfoParts)
|
|
|
|
/*!
|
|
* \brief Returns the configuration of the manager.
|
|
* \remarks The configuration has been specified when constructing the manager.
|
|
*/
|
|
inline const Config &Manager::config() const
|
|
{
|
|
return m_config;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns whether the manager writes cache files for all relevant repositories before the manager is
|
|
* gone (out of scope, deleted, ...).
|
|
* \sa setWriteCacheBeforeGone()
|
|
*/
|
|
inline bool Manager::writeCacheBeforeGone() const
|
|
{
|
|
return m_writeCacheBeforeGone;
|
|
}
|
|
|
|
/*!
|
|
* \brief Sets whether the manager writes cache files for all relevant repositories before the manager is
|
|
* gone (out of scope, deleted, ...).
|
|
* \sa writeCacheBeforeGone()
|
|
*/
|
|
inline void Manager::setWriteCacheBeforeGone(bool writeCacheBeforeGone)
|
|
{
|
|
m_writeCacheBeforeGone = writeCacheBeforeGone;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the signature level.
|
|
*
|
|
* The signature level is read from the pacman config
|
|
* when parsePacmanConfig() is called or can be set
|
|
* manually using setSigLevel().
|
|
*/
|
|
inline int Manager::sigLevel() const
|
|
{
|
|
return m_sigLevel;
|
|
}
|
|
|
|
/*!
|
|
* \brief Sets the signature level.
|
|
*/
|
|
inline void Manager::setSigLevel(int sigLevel)
|
|
{
|
|
m_sigLevel = sigLevel;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the signature level used when opening local files.
|
|
*
|
|
* The signature level is read from the pacman config
|
|
* when parsePacmanConfig() is called or can be set
|
|
* manually using setSigLevel().
|
|
*/
|
|
inline int Manager::localFileSigLevel() const
|
|
{
|
|
return m_localFileSigLevel;
|
|
}
|
|
|
|
/*!
|
|
* \brief Sets the signature level used when opening local files.
|
|
*/
|
|
inline void Manager::setLocalFileSigLevel(int sigLevel)
|
|
{
|
|
m_localFileSigLevel = sigLevel;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns whether the specified \a package is ignored.
|
|
*/
|
|
inline bool Manager::isPackageIgnored(const AlpmPackage *package) const
|
|
{
|
|
return alpm_pkg_should_ignore(m_handle, const_cast<alpm_pkg_t *>(package->ptr()));
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the Pacman cache directory.
|
|
* \remarks This is read from the Pacman configuration.
|
|
*/
|
|
inline const QString &Manager::pacmanCacheDir() const
|
|
{
|
|
return m_pacmanCacheDir;
|
|
}
|
|
|
|
inline const UserRepository *Manager::userRepository() const
|
|
{
|
|
return m_userRepo.get();
|
|
}
|
|
|
|
inline UserRepository *Manager::userRepository()
|
|
{
|
|
return m_userRepo.get();
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the local data base.
|
|
*/
|
|
inline const AlpmDatabase *Manager::localDataBase() const
|
|
{
|
|
return m_localDb.get();
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the local data base.
|
|
*/
|
|
inline AlpmDatabase *Manager::localDataBase()
|
|
{
|
|
return m_localDb.get();
|
|
}
|
|
|
|
}
|
|
|
|
#endif // ALPM_MANAGER_H
|