#include "./alpmpackage.h" #include "./alpmdatabase.h" #include "./utilities.h" #include #include #include #include using namespace ChronoUtilities; namespace RepoIndex { /*! * \brief The AlpmPackage class wraps an ALPM package struct and holds additional meta information. */ /*! * \brief Constructs an empty ALPM package for the specified \a repository. * \remarks This constructor is called by the AlpmDatabase class which puts the package name and * available meta data via the Package::putDescription() method. */ AlpmPackage::AlpmPackage(AlpmDatabase *repository) : Package(QString(), repository) {} AlpmPackage::AlpmPackage(const QString &packageFilePath) : Package(QString(), nullptr) { m_origin = PackageOrigin::File; m_name = m_fileName = QFileInfo(packageFilePath).fileName(); Utilities::stripVersion(m_name); KTar pkgTar(packageFilePath); const KArchiveDirectory *mainDir; if(pkgTar.open(QIODevice::ReadOnly) && (mainDir = pkgTar.directory())) { if(const KArchiveEntry *pkgInfoEntry = mainDir->entry(QStringLiteral(".PKGINFO"))) { if(pkgInfoEntry->isFile()) { // parse fields QList > packageInfo; AlpmDatabase::parsePkgInfo(static_cast(pkgInfoEntry)->data(), m_name, packageInfo); putInfo(QList >(), packageInfo, true); } else { // TODO: handle error (.PKGINFO is not a file) } } } else { // TODO: handle error (can't open package file) } } } // namespace PackageManagement