Commit 2f57dd41 authored by Dario Freddi's avatar Dario Freddi

Compress deltas

Signed-off-by: default avatarDario Freddi <drf@kde.org>
parent 8aa8eee0
......@@ -63,7 +63,7 @@ QString CreateDb::cleanPath(const QString &path)
return QDir::cleanPath(retpath);
}
bool CreateDb::writeArchive(const QString &dbname, const QString& filename, const QHash< QString, QString >& files)
bool CreateDb::writeArchive(const QString& filename, const QHash< QString, QString >& files)
{
struct archive *a;
struct archive_entry *entry;
......@@ -214,7 +214,7 @@ void CreateDb::start()
foreach (const QString &target, cleanTargets) {
++idx;
// Is it a delta?
if (target.endsWith(".delta")) {
if (target.endsWith(".delta.tar.xz")) {
// It is. Let's try having a look at what it is. The delta naming format is <name>-<vfrom>_to_<vto>.delta
QStringList targetSplitted = target.split('-');
QString tName = targetSplitted.first().split('/').last();
......@@ -315,14 +315,27 @@ void CreateDb::start()
proc.start(command);
proc.waitForFinished(600000);
if (proc.exitCode() == 0) {
// Ok, now compress the delta
out << "Done!" << endl;
out << '\t' << "Compressing delta... ";
out.flush();
QHash<QString,QString> files;
files.insert(deltaName.split('/').last(), deltaName);
deltaName += ".tar.xz";
if (!writeArchive(deltaName, files)) {
out << "Failed! Could not compress the delta. Skipping..." << endl;
continue;
}
out << "Done!" << endl;
// Done. Is the delta convenient?
QFileInfo deltaInfo(deltaName);
qDebug() << deltaInfo.size() << (*j)->size() << (deltaInfo.size() * 100) / (*j)->size();
if ( (deltaInfo.size() * 100) / (*j)->size() > 40 ) {
// It's over 40% of the size. Screw it.
QFile::remove(deltaName);
out << "The delta does not respect size constraints, ratio delta size/ package size is "
<< (deltaInfo.size() * 100) / (*j)->size() << " skipping..." << endl;
out << '\t' << "The delta does not respect size constraints, ratio delta size/package size is "
<< (deltaInfo.size() * 100) / (*j)->size() << "%, skipping..." << endl;
continue;
}
// Insert it!
......@@ -433,7 +446,7 @@ void CreateDb::start()
files.insert(dbName + ".db", path);
// files.insert(dbName + '/' + dbName + ".files", ftf.fileName());
if (!writeArchive(dbName, compressedDbPath, files)) {
if (!writeArchive(compressedDbPath, files)) {
out << "Failed! Could not compress the db." << endl;
QCoreApplication::instance()->exit(1);
return;
......
......@@ -28,7 +28,7 @@ class CreateDb : public QObject
private:
QString cleanPath(const QString &path);
bool writeArchive(const QString &dbname, const QString &filename, const QHash<QString,QString> &files);
bool writeArchive(const QString &filename, const QHash<QString,QString> &files);
private:
QString m_db;
......
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