repoindex/lib/alpm/alpmpackage.cpp

54 lines
1.7 KiB
C++
Raw Normal View History

#include "./alpmpackage.h"
#include "./alpmdatabase.h"
#include "./utilities.h"
2015-09-04 14:37:01 +02:00
2016-02-14 23:48:43 +01:00
#include <KTar>
#include <KArchiveDirectory>
#include <KArchiveFile>
2015-09-04 14:37:01 +02:00
2016-02-14 23:48:43 +01:00
#include <QFileInfo>
2019-06-10 22:51:09 +02:00
using namespace CppUtilities;
2015-09-04 14:37:01 +02:00
namespace RepoIndex {
2015-09-04 14:37:01 +02:00
/*!
* \brief The AlpmPackage class wraps an ALPM package struct and holds additional meta information.
*/
2016-02-12 01:05:08 +01:00
/*!
2016-02-14 23:48:43 +01:00
* \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.
2016-02-12 01:05:08 +01:00
*/
AlpmPackage::AlpmPackage(AlpmDatabase *repository) :
2016-02-14 23:48:43 +01:00
Package(QString(), repository)
2016-02-12 01:05:08 +01:00
{}
2016-02-14 23:48:43 +01:00
AlpmPackage::AlpmPackage(const QString &packageFilePath) :
Package(QString(), nullptr)
2015-09-04 14:37:01 +02:00
{
2016-02-14 23:48:43 +01:00
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)
}
2015-09-04 14:37:01 +02:00
}
2016-02-14 23:48:43 +01:00
} else {
// TODO: handle error (can't open package file)
2015-09-04 14:37:01 +02:00
}
}
} // namespace PackageManagement