257 lines
6.6 KiB
C++
257 lines
6.6 KiB
C++
#ifndef ALPM_DATABASE_H
|
|
#define ALPM_DATABASE_H
|
|
|
|
#include "list.h"
|
|
#include "updatelookup.h"
|
|
|
|
#include <alpm.h>
|
|
|
|
#include <QJsonArray>
|
|
#include <QList>
|
|
|
|
#include <map>
|
|
|
|
namespace PackageManagement {
|
|
|
|
class AlpmDataBase
|
|
{
|
|
public:
|
|
AlpmDataBase(alpm_db_t *dataBase = nullptr, const QString &dbFile = QString(), const QString &srcDir = QString(), const QString &pkgDir = QString());
|
|
|
|
// operators
|
|
operator bool() const;
|
|
bool operator ==(const AlpmDataBase &other) const;
|
|
bool operator !=(const AlpmDataBase &other) const;
|
|
|
|
// database properties
|
|
alpm_db_t *ptr() const;
|
|
const char *name() const;
|
|
const QString &dataBaseFile() const;
|
|
const QString &sourcesDirectory() const;
|
|
void setSourcesDirectory(const QString &dir);
|
|
const QString &packagesDirectory() const;
|
|
void setPackagesDirectory(const QString &dir);
|
|
alpm_siglevel_t sigLevel() const;
|
|
alpm_db_usage_t usage() const;
|
|
StringList servers() const;
|
|
bool setServers(StringList servers);
|
|
const QJsonArray &serverUrls() const;
|
|
bool addServerUrls(const QStringList &urls);
|
|
alpm_pkg_t *package(const char *name) const;
|
|
const std::map<QString, AlpmPackage> &packages() const;
|
|
QStringList packageNames() const;
|
|
const QJsonArray &packageNameJsonArray() const;
|
|
alpm_group_t *group(const char *name) const;
|
|
GroupList groups() const;
|
|
QJsonObject groupInfo() const;
|
|
PackageList search(StringList terms) const;
|
|
|
|
// upgrade lookup
|
|
const QStringList &upgradeSources() const;
|
|
QStringList &upgradeSources();
|
|
template<class SyncPackageType>
|
|
void checkForUpgrades(const std::map<QString, SyncPackageType> &syncDbPkgs, UpdateLookupResults<SyncPackageType> &results) const;
|
|
void checkForUpgrades(const QList<const AlpmDataBase *> &syncDbs, UpdateLookupResults<AlpmPackage> &results) const;
|
|
|
|
private:
|
|
alpm_db_t *m_ptr;
|
|
QString m_dbFile;
|
|
QString m_srcDir;
|
|
QString m_pkgDir;
|
|
QStringList m_upgradeSources;
|
|
mutable QJsonArray m_serverUrls;
|
|
mutable std::map<QString, AlpmPackage> m_packages;
|
|
mutable QJsonArray m_packageNamesJsonArray;
|
|
mutable QJsonArray m_groupInfo;
|
|
};
|
|
|
|
/*!
|
|
* \brief Creates a new instance wrapping the specified database struct.
|
|
*/
|
|
inline AlpmDataBase::AlpmDataBase(alpm_db_t *dataBase, const QString &dbFile, const QString &srcDir, const QString &pkgDir) :
|
|
m_ptr(dataBase),
|
|
m_dbFile(dbFile),
|
|
m_srcDir(srcDir),
|
|
m_pkgDir(pkgDir)
|
|
{}
|
|
|
|
/*!
|
|
* \brief Checks whether the specified ALPM database is equal to the current instance.
|
|
*/
|
|
inline bool AlpmDataBase::operator ==(const AlpmDataBase &other) const
|
|
{
|
|
return m_ptr == other.m_ptr;
|
|
}
|
|
|
|
/*!
|
|
* \brief Checks whether the specified ALPM database is not equal to the current instance.
|
|
*/
|
|
inline bool AlpmDataBase::operator !=(const AlpmDataBase &other) const
|
|
{
|
|
return m_ptr != other.m_ptr;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the pointer to the underlying database struct.
|
|
*/
|
|
inline alpm_db_t *AlpmDataBase::ptr() const
|
|
{
|
|
return m_ptr;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the name of the database.
|
|
*/
|
|
inline const char *AlpmDataBase::name() const
|
|
{
|
|
return alpm_db_get_name(m_ptr);
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the path of the data base file.
|
|
*/
|
|
inline const QString &AlpmDataBase::dataBaseFile() const
|
|
{
|
|
return m_dbFile;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the path of the local sources directory.
|
|
*/
|
|
inline const QString &AlpmDataBase::sourcesDirectory() const
|
|
{
|
|
return m_srcDir;
|
|
}
|
|
|
|
/*!
|
|
* \brief Sets the path of the local sources directory.
|
|
*/
|
|
inline void AlpmDataBase::setSourcesDirectory(const QString &dir)
|
|
{
|
|
m_srcDir = dir;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the path of the local packages directory.
|
|
*/
|
|
inline const QString &AlpmDataBase::packagesDirectory() const
|
|
{
|
|
return m_pkgDir;
|
|
}
|
|
|
|
/*!
|
|
* \brief Sets the path of the local packages directory.
|
|
*/
|
|
inline void AlpmDataBase::setPackagesDirectory(const QString &dir)
|
|
{
|
|
m_pkgDir = dir;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the signature level of the database.
|
|
*/
|
|
inline alpm_siglevel_t AlpmDataBase::sigLevel() const
|
|
{
|
|
return alpm_db_get_siglevel(m_ptr);
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the servers of the database.
|
|
*/
|
|
inline StringList AlpmDataBase::servers() const
|
|
{
|
|
return alpm_db_get_servers(m_ptr);
|
|
}
|
|
|
|
/*!
|
|
* \brief Sets the servers of the database.
|
|
*/
|
|
inline bool AlpmDataBase::setServers(StringList servers)
|
|
{
|
|
return alpm_db_set_servers(m_ptr, servers.begin().ptr()) == 0;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the package with the specified \a name.
|
|
*/
|
|
inline alpm_pkg_t *AlpmDataBase::package(const char *name) const
|
|
{
|
|
return alpm_db_get_pkg(m_ptr, name);
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the groups.
|
|
*/
|
|
inline alpm_group_t *AlpmDataBase::group(const char *name) const
|
|
{
|
|
return alpm_db_get_group(m_ptr, name);
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the groups.
|
|
*/
|
|
inline GroupList AlpmDataBase::groups() const
|
|
{
|
|
return alpm_db_get_groupcache(m_ptr);
|
|
}
|
|
|
|
/*!
|
|
* \brief Performs a search using the build in ALPM function.
|
|
*/
|
|
inline PackageList AlpmDataBase::search(StringList terms) const
|
|
{
|
|
return alpm_db_search(m_ptr, terms.begin().ptr());
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns a list of databases which are used (by default) to upgrade this database.
|
|
*/
|
|
inline const QStringList &AlpmDataBase::upgradeSources() const
|
|
{
|
|
return m_upgradeSources;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns a list of databases which are used (by default) to upgrade this database.
|
|
*/
|
|
inline QStringList &AlpmDataBase::upgradeSources()
|
|
{
|
|
return m_upgradeSources;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns whether the database instance is valid or null.
|
|
*/
|
|
inline PackageManagement::AlpmDataBase::operator bool() const
|
|
{
|
|
return m_ptr != nullptr;
|
|
}
|
|
|
|
template<class SyncPackageType>
|
|
void AlpmDataBase::checkForUpgrades(const std::map<QString, SyncPackageType> &syncDbPkgs, UpdateLookupResults<SyncPackageType> &results) const
|
|
{
|
|
for(const auto &dbPkg : packages()) {
|
|
try {
|
|
const auto &syncPkg = syncDbPkgs.at(dbPkg.first);
|
|
switch(dbPkg.second.compareVersion(syncPkg)) {
|
|
case PackageVersionComparsion::Equal:
|
|
break; // ignore equal packages
|
|
case PackageVersionComparsion::SoftwareUpgrade:
|
|
results.newVersions << makeUpdateResult(syncPkg, dbPkg.second.version());
|
|
break;
|
|
case PackageVersionComparsion::PackageUpgradeOnly:
|
|
results.newReleases << makeUpdateResult(syncPkg, dbPkg.second.version());
|
|
break;
|
|
case PackageVersionComparsion::NewerThenSyncVersion:
|
|
results.downgrades << makeUpdateResult(syncPkg, dbPkg.second.version());
|
|
}
|
|
} catch(std::out_of_range &) {
|
|
results.orphaned << dbPkg.second;
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace Alpm
|
|
|
|
#endif // ALPM_DATABASE_H
|