repoindex/lib/alpm/alpmpackage.cpp

54 lines
1.7 KiB
C++

#include "./alpmpackage.h"
#include "./alpmdatabase.h"
#include "./utilities.h"
#include <KTar>
#include <KArchiveDirectory>
#include <KArchiveFile>
#include <QFileInfo>
using namespace CppUtilities;
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<QPair<QString, QString> > packageInfo;
AlpmDatabase::parsePkgInfo(static_cast<const KArchiveFile *>(pkgInfoEntry)->data(), m_name, packageInfo);
putInfo(QList<QPair<QString, QString> >(), packageInfo, true);
} else {
// TODO: handle error (.PKGINFO is not a file)
}
}
} else {
// TODO: handle error (can't open package file)
}
}
} // namespace PackageManagement