Commit 707d1b3e authored by Lukas Appelhans's avatar Lukas Appelhans

Complete handling of backup files

parent d5527ec7
......@@ -112,7 +112,19 @@ void PlainInstallOperation::run()
/* libarchive requires this for extracting hard links */
chdir(Config::instance()->root().toUtf8().data());
QStringList backup = d->package->backupFiles();
for (int i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; ++i) {
if (backup.contains(archive_entry_pathname(entry)) && QFile::exists(archive_entry_pathname(entry))) {
QString file = Config::instance()->rootDir().absoluteFilePath(archive_entry_pathname(entry));
bool done = QFile::rename(file, file + ".akabeisave");
if (done) {
addMessage(QObject::tr("Akabei found an existing config and moved it to %1...").arg(file + ".akabeisave"));
} else {
addMessage(QObject::tr("Akabei found an existing config, but had a problem to move it to %1."
"Maybe an old config was still in place. Please fix it yourself!").arg(file + ".akabeisave"));
}
}
int percent;
if (d->package->size() != 0) {
......@@ -237,7 +249,12 @@ void PlainInstallOperation::validate()
// Now let's set the conflicting targets & stuff.
// Since this is an installation, we're adding stuff to the filesystem
if (!(processingOptions() & Akabei::Force)) {
setFileSystemAdditions(d->package->retrieveFiles());
QStringList additions = d->package->retrieveFiles();
foreach (const QString &file, d->package->backupFiles()) {
if (QFile::exists(Config::instance()->rootDir().absoluteFilePath(file)))
additions.removeAll(file);
}
setFileSystemAdditions(additions);
}
// If it has a scriptlet, we need a new suboperation
......
......@@ -103,7 +103,7 @@ void PlainReInstallOperation::run()
file = Config::instance()->rootDir().absoluteFilePath(file);
if ((file.endsWith('/') && !QFileInfo(file).isSymLink()) || (backup.contains(file) && !backup[file].isEmpty())) {
++idx;
// It's a directory
// It's a directory (or something else we don't want to remove :D)
continue;
}
if (QFile::remove(file) && !(processingOptions() & Akabei::Force)) {
......
......@@ -18,6 +18,9 @@
#include <QtCore/QStringList>
#include <akabeihelpers.h>
#include <sqlite3.h>
#include <QFileInfo>
#include <QDir>
#include <akabeiconfig.h>
#include "akabeiplainscriptletoperation.h"
namespace Akabei {
......@@ -51,10 +54,20 @@ void PlainRemoveOperation::run()
{
// Remove all files
if (!(processingOptions() & Akabei::DatabaseOnly)) {
QHash<QString, QString> backup;
foreach (const QString &file, d->package->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());
}
int idx = 0;
int filesSize = d->package->retrieveFiles().size();
foreach (const QString &file, d->package->retrieveFiles()) {
if (file.endsWith('/')) { //TODO: Also remove dirs when there are no other files in it at the end
if ((file.endsWith('/') && !QFileInfo(file).isSymLink()) || backup.contains(file)) {
++idx;
// It's a directory
continue;
}
......
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