Commit f9cb62e4 authored by Lukas Appelhans's avatar Lukas Appelhans

Handle symlinks and don't overwrite configs all the time... yay!

parent 26da19ca
......@@ -715,7 +715,10 @@ Package* Package::generateInstalledPackage(Package::InstallReason ireason, const
Package *p = new Package(0, -1, name());
p->d_func()->arch = d->arch;
p->d_func()->pathToArchive = d->pathToArchive;
p->d_func()->backup = d->backup;
QStringList backInclMd5;
foreach (const QString &b, d->backup) //Construct some file=md5sum scheme to later know what the original file was
backInclMd5 << b + '=' + Helpers::md5sumOfFile(Config::instance()->rootDir().absoluteFilePath(b));
p->d_func()->backup = backInclMd5;
p->d_func()->buildDate = d->buildDate;
p->d_func()->conflicts = d->conflicts;
p->d_func()->deps = d->deps;
......
......@@ -111,7 +111,7 @@ void PlainInstallOperation::run()
/* libarchive requires this for extracting hard links */
chdir(Config::instance()->root().toUtf8().data());
for (int i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; ++i) {
int percent;
......@@ -129,7 +129,7 @@ void PlainInstallOperation::run()
}
setProgress(percent);
/* extract the next file from the archive */
errs += Helpers::extract_single_file(archive, entry, processingOptions() & Akabei::Force);
}
......
......@@ -25,11 +25,13 @@
#include <akabeihelpers.h>
#include <QtCore/QDir>
#include <QDebug>
#include <QTemporaryFile>
#include <akabeiconfig.h>
#include <akabeibackend.h>
#include <sqlite3.h>
#include <akabeierror.h>
#include <akabeicore/akabeidatabase.h>
namespace Akabei {
......@@ -82,17 +84,30 @@ void PlainReInstallOperation::run()
return;
}
QHash<QString, QString> backup;
foreach (const QString &file, Backend::instance()->localDatabase()->queryPackages("SELECT * from packages WHERE NAME LIKE \"" + d->package->name() + "\"").first()->backupFiles()) {
QStringList split = file.split('=');
if (split.count() >= 2)
backup.insert(Config::instance()->rootDir().absoluteFilePath(split.first()), split.last());
else
backup.insert(Config::instance()->rootDir().absoluteFilePath(file), QString());
}
// Remove first
// Remove all files
int idx = 0;
int filesSize = d->package->retrieveFiles().size();
foreach (const QString &file, d->package->retrieveFiles()) {
if (file.endsWith('/')) {
foreach (const QString &f, d->package->retrieveFiles()) {
QString file = f;
if (d->package->database() != Backend::instance()->localDatabase())
file = Config::instance()->rootDir().absoluteFilePath(file);
if ((file.endsWith('/') && !QFileInfo(file).isSymLink()) || (backup.contains(file) && !backup[file].isEmpty())) {
++idx;
// It's a directory
continue;
}
if (QFile::remove(file) && !(processingOptions() & Akabei::Force)) {
setErrors(QList<Akabei::Error*>() << new Akabei::Error(Akabei::Error::UnknownError, QObject::tr("Removing one file failed!"), this));
setErrors(QList<Akabei::Error*>() << new Akabei::Error(Akabei::Error::UnknownError, QObject::tr("Removing %1 file failed!").arg(file), this));
setFinished(false);
}
++idx;
......@@ -125,6 +140,33 @@ void PlainReInstallOperation::run()
chdir(Config::instance()->root().toUtf8().data());
for(int i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; ++i) {
QString path = Config::instance()->rootDir().absoluteFilePath(archive_entry_pathname(entry));
bool overwrite = false;
if (backup.contains(path) && !backup[path].isEmpty()) {
//Get two of the 3 possible md5sums
QByteArray originalMD5Sum = backup[path].toAscii();
QByteArray onDiskMd5Sum = Helpers::md5sumOfFile(path);
//First extract the new file then check the md5sum
QString newDiskPath = "tmp/akabei_" + path.split('/').last();
archive_entry_set_pathname(entry, newDiskPath.toStdString().c_str());
int ret = Helpers::extract_single_file(archive, entry, true);
newDiskPath = Config::instance()->rootDir().absoluteFilePath(newDiskPath);//extract_single_file is chdir to the rootDir()
QByteArray newMd5sum = Helpers::md5sumOfFile(newDiskPath);
if (originalMD5Sum == newMd5sum) {
continue;
}
if (onDiskMd5Sum != originalMD5Sum && newMd5sum != onDiskMd5Sum && newMd5sum != onDiskMd5Sum && !onDiskMd5Sum.isEmpty()) {
path = path + ".akabei";
addMessage(QObject::tr("Installing new config to %1. Please merge manually!").arg(path));
qDebug() << "Copying file to" << path;
QFile::copy(newDiskPath, path);
continue;
} else {
overwrite = true;
}
}
int percent;
if (d->package->size() != 0) {
......@@ -142,8 +184,7 @@ void PlainReInstallOperation::run()
setProgress((percent / 2) + 50);
/* extract the next file from the archive */
errs += Helpers::extract_single_file(archive, entry, processingOptions() & Akabei::Force);
errs += Helpers::extract_single_file(archive, entry, (processingOptions() & Akabei::Force) || overwrite);
}
archive_read_finish(archive);
......@@ -153,7 +194,7 @@ void PlainReInstallOperation::run()
}
if(errs && !(processingOptions() & Akabei::Force)) {
setErrors(QList<Akabei::Error*>() << new Akabei::Error(Akabei::Error::FilesystemConflictError, QObject::tr("There have been %1 file conflict(s).", "", errs), this));
setErrors(QList<Akabei::Error*>() << new Akabei::Error(Akabei::Error::FilesystemConflictError, QObject::tr("There have been %1 file conflict(s).").arg(errs), this));
setFinished(false);
return;
}
......
......@@ -27,6 +27,7 @@
#include <sqlite3.h>
#include <akabeierror.h>
#include <QTemporaryFile>
namespace Akabei {
......@@ -80,17 +81,28 @@ void PlainUpgradeOperation::run()
return;
}
QHash<QString, QString> backup = Helpers::versionedTargets(d->from->backupFiles());
foreach (const QString &file, Helpers::versionedTargets(d->from->backupFiles())) {
QStringList split = file.split('=');
if (split.count() >= 2)
backup.insert(Config::instance()->rootDir().absoluteFilePath(split.first()), split.last());
else
backup.insert(Config::instance()->rootDir().absoluteFilePath(file), QString());
}
// Remove first
// Remove all files
int idx = 0;
int filesSize = d->from->retrieveFiles().size();
foreach (const QString &file, d->from->retrieveFiles()) {
if (file.endsWith('/')) {
foreach (const QString &f, d->from->retrieveFiles()) {
QString file = f;
if ((file.endsWith('/') && !QFileInfo(file).isSymLink()) || (backup.contains(file) && !backup[file].isEmpty())) {
++idx;
// It's a directory
continue;
}
if (QFile::remove(file) && !(processingOptions() & Akabei::Force)) {
setErrors(QList<Akabei::Error*>() << new Akabei::Error(Akabei::Error::UnknownError, QObject::tr("Removing one file failed!"), this));
setErrors(QList<Akabei::Error*>() << new Akabei::Error(Akabei::Error::UnknownError, QObject::tr("Removing %1 file failed!").arg(file), this));
setFinished(false);
}
++idx;
......@@ -123,9 +135,36 @@ void PlainUpgradeOperation::run()
chdir(Config::instance()->root().toUtf8().data());
for(int i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; ++i) {
QString path = Config::instance()->rootDir().absoluteFilePath(archive_entry_pathname(entry));
bool overwrite = false;
if (backup.contains(path) && !backup[path].isEmpty()) {
//Get two of the 3 possible md5sums
QByteArray originalMD5Sum = backup[path].toAscii();
QByteArray onDiskMd5Sum = Helpers::md5sumOfFile(path);
//First extract the new file then check the md5sum
QString newDiskPath = "tmp/akabei_" + path.split('/').last();
archive_entry_set_pathname(entry, newDiskPath.toStdString().c_str());
int ret = Helpers::extract_single_file(archive, entry, true);
newDiskPath = Config::instance()->rootDir().absoluteFilePath(newDiskPath);//extract_single_file is chdir to the rootDir()
QByteArray newMd5sum = Helpers::md5sumOfFile(newDiskPath);
if (originalMD5Sum == newMd5sum) {
continue;
}
if (onDiskMd5Sum != originalMD5Sum && newMd5sum != onDiskMd5Sum && newMd5sum != onDiskMd5Sum && !onDiskMd5Sum.isEmpty()) {
path = path + ".akabei";
addMessage(QObject::tr("Installing new config to %1. Please merge manually!").arg(path));
qDebug() << "Copying file to" << path;
QFile::copy(newDiskPath, path);
continue;
} else {
overwrite = true;
}
}
int percent;
if(d->to->size() != 0) {
if (d->to->size() != 0) {
/* Using compressed size for calculations here, as newpkg->isize is not
* exact when it comes to comparing to the ACTUAL uncompressed size
* (missing metadata sizes) */
......@@ -140,8 +179,7 @@ void PlainUpgradeOperation::run()
setProgress((percent / 2) + 50);
/* extract the next file from the archive */
errs += Helpers::extract_single_file(archive, entry, processingOptions() & Akabei::Force);
errs += Helpers::extract_single_file(archive, entry, (processingOptions() & Akabei::Force) || overwrite);
}
archive_read_finish(archive);
......@@ -151,7 +189,7 @@ void PlainUpgradeOperation::run()
}
if(errs && !(processingOptions() & Akabei::Force)) {
setErrors(QList<Akabei::Error*>() << new Akabei::Error(Akabei::Error::FilesystemConflictError, QObject::tr("There have been %1 file conflict(s).", "", errs), this));
setErrors(QList<Akabei::Error*>() << new Akabei::Error(Akabei::Error::FilesystemConflictError, QObject::tr("There have been %1 file conflict(s).").arg(errs), this));
setFinished(false);
return;
}
......
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