Commit 3d64077f authored by Dario Freddi's avatar Dario Freddi

Make the whole delta implementatio work

Signed-off-by: default avatarDario Freddi <drf@kde.org>
parent 2f57dd41
......@@ -50,6 +50,7 @@ CREATE TABLE "groups" (
CREATE TABLE "deltas" (
"ID" INTEGER PRIMARY KEY AUTOINCREMENT,
"Package" INTEGER,
"Filename" TEXT,
"VersionFrom" TEXT,
"VersionTo" TEXT,
"MD5SUM" TEXT
......
......@@ -15,6 +15,7 @@
#include "akabeigroup.h"
#include "akabeipackage_p.h"
#include "akabeihelpers_p.h"
#include "akabeidelta_p.h"
#include <QtCore/QHash>
#include <QtCore/QtConcurrentRun>
......@@ -557,6 +558,121 @@ Package* Backend::loadPackageFromFile(const QString& path)
return retpackage;
}
Delta* Backend::loadDeltaFromFile(const QString& path)
{
int ret = ARCHIVE_OK;
struct archive *archive;
struct archive_entry *entry;
if (!QFile::exists(path)) {
return 0;
}
if((archive = archive_read_new()) == NULL) {
// RET_ERR(PM_ERR_LIBARCHIVE, NULL);
return 0;
}
archive_read_support_compression_all(archive);
archive_read_support_format_all(archive);
if (archive_read_open_filename(archive, path.toUtf8().data(), ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
// RET_ERR(PM_ERR_PKG_OPEN, NULL);
return 0;
}
Delta *retdelta = new Delta(QString(), QByteArray(), QByteArray());
retdelta->d_func()->pathToDelta = path;
/* If full is false, only read through the archive until we find our needed
* metadata. If it is true, read through the entire archive, which serves
* as a verfication of integrity and allows us to create the filelist. */
while((ret = archive_read_next_header(archive, &entry)) == ARCHIVE_OK) {
const char *entry_name = archive_entry_pathname(entry);
if(strcmp(entry_name, ".DELTAINFO") == 0) {
// Go and read from the archive
char fline[512];
while (Helpers::archive_file_readline(archive, fline) != 0) {
QString line(fline);
if (!line.contains('=') || line.startsWith('#')) {
// Skip this line, not interesting
continue;
}
line.remove('\n');
// Separate the two strings
QStringList splitted = line.split('=');
QString key = splitted.first();
// There might be an equal, so
splitted.removeAt(0);
QString value = splitted.join(QChar('='));
// Just remove all spaces ignorantly here
key = key.remove(' ');
// Recheck if it's commented over
if (key.startsWith('#')) {
// Pass by
}
// Strip whitespaces here instead
while (value.startsWith(' ')) {
value = value.remove(0, 1);
}
while (value.endsWith(' ')) {
value = value.remove(value.length() - 1, 1);
}
// Ok, now let's analyze
if (key == "pkgname") {
retdelta->d_func()->name = value;
} else if (key == "verfrom") {
retdelta->d_func()->vFrom = value.toUtf8();
} else if (key == "verto") {
retdelta->d_func()->vTo = value.toUtf8();
}
}
continue;
} else if(*entry_name == '.') {
/* for now, ignore all files starting with '.' that haven't
* already been handled (for future possibilities) */
} else {
// It can be only our delta
if (entry_name != path.split('/').last().remove(".tar.xz")) {
delete retdelta;
return 0;
}
}
if (archive_read_data_skip(archive)) {
delete retdelta;
return 0;
}
}
// Some checks
if (ret != ARCHIVE_EOF) {
delete retdelta;
return 0;
}
if (retdelta->targetName().isEmpty()) {
delete retdelta;
return 0;
}
// Now add md5sum and filename, of course
retdelta->d_func()->filename = path.split('/').last();
retdelta->d_func()->md5sum = Helpers::md5sumOfFile(path);
// We already computed md5 and validation, so set em up
retdelta->d_func()->_p_md5checked = true;
retdelta->d_func()->_p_validated = true;
return retdelta;
}
}
#include "akabeibackend.moc"
......@@ -17,6 +17,7 @@
class QUuid;
namespace Akabei {
class Delta;
class OperationRunner;
class Group;
class Package;
......@@ -58,6 +59,7 @@ class AKABEICORESHARED_EXPORT Backend : public QObject
OperationRunner *operationRunner();
Package *loadPackageFromFile(const QString &path);
Delta *loadDeltaFromFile(const QString &path);
public Q_SLOTS:
void initialize();
......
......@@ -14,7 +14,7 @@
namespace Akabei
{
Delta::Delta(const QString& targetName, const QString& versionFrom, const QString& versionTo)
Delta::Delta(const QString& targetName, const QByteArray& versionFrom, const QByteArray& versionTo)
: d_ptr(new DeltaPrivate(targetName, versionFrom, versionTo))
{
}
......@@ -48,12 +48,6 @@ QString Delta::filename() const
return d->filename;
}
QString Delta::filenameFrom() const
{
Q_D(const Delta);
return d->filenameFrom;
}
QByteArray Delta::md5sum() const
{
Q_D(const Delta);
......@@ -90,13 +84,13 @@ QString Delta::targetName() const
return d->name;
}
QString Delta::versionFrom() const
QByteArray Delta::versionFrom() const
{
Q_D(const Delta);
return d->vFrom;
}
QString Delta::versionTo() const
QByteArray Delta::versionTo() const
{
Q_D(const Delta);
return d->vTo;
......
......@@ -26,11 +26,10 @@ class Delta {
QByteArray md5sum() const;
QString targetName() const;
QString versionFrom() const;
QString versionTo() const;
QByteArray versionFrom() const;
QByteArray versionTo() const;
QString filename() const;
QString filenameFrom() const;
bool checkMD5Sum();
......@@ -43,10 +42,11 @@ class Delta {
void setPathToSource(const QString &path);
private:
Delta(const QString &targetName, const QString &versionFrom, const QString &versionTo);
Delta(const QString &targetName, const QByteArray &versionFrom, const QByteArray &versionTo);
DeltaPrivate * const d_ptr;
friend class Backend;
friend class Database;
friend class DatabasePrivate;
};
......
......@@ -18,27 +18,29 @@ namespace Akabei {
class DeltaPrivate {
public:
DeltaPrivate(const QString &n, const QString &v1, const QString &v2)
DeltaPrivate(const QString &n, const QByteArray &v1, const QByteArray &v2)
: name(n)
, vFrom(v1)
, vTo(v2)
, _p_md5checked(false)
, _p_validated(false)
{}
~DeltaPrivate() {}
QString name;
QByteArray md5sum;
QString vFrom;
QString vTo;
QByteArray vFrom;
QByteArray vTo;
QString filename;
QString filenameFrom;
QString pathToDelta;
QString pathToOldFile;
QString xdeltaApply;
bool _p_md5checked;
bool _p_validated;
};
}
......
This diff is collapsed.
......@@ -15,6 +15,7 @@
#include <QtCore/QStringList>
#include <QtCore/QTextStream>
#include <QtCore/QHash>
#include <sqlite3.h>
class CreateDb : public QObject
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment