Commit 46142e97 authored by Lukas Appelhans's avatar Lukas Appelhans
Browse files

Remove dirs when they are empty

parent c6cc00cc
......@@ -503,7 +503,6 @@ Backend::Backend(QObject* parent)
: QObject(parent)
, d_ptr(new BackendPrivate(this))
{
qDebug() << "We are running in threadSSSSSSSSSSSSSSSSSSSSSSSSS" << QThread::currentThread();
Q_ASSERT(!s_globalBackend()->q);
s_globalBackend()->q = this;
qRegisterMetaType<QUuid>();
......
......@@ -95,7 +95,9 @@ class BackendPrivate : public QObject
void __k__initializationFinished();
void __k__lockGranted(qlonglong pid);
void __k__lockGranted() { __k__lockGranted(QCoreApplication::applicationPid()); }
void __k__lockGranted() {
__k__lockGranted(QCoreApplication::applicationPid());
}
void getLock();
QHash<QString, Database*> performInitialization();
......
......@@ -30,7 +30,8 @@ DatabasePrivate::DatabasePrivate(Database* db, QString const& pathToDatabase)
if (!QFile::exists(pathToDatabase)) {
qDebug() << "Caught this";
error.setType(Error::DatabaseError);
error.setDescription(QObject::tr("Cannot find database file on disk: %1").arg(pathToDatabase));
error.setDescription(QObject::tr("Cannot find database file on disk: %1!").arg(pathToDatabase));
Akabei::ErrorQueue::instance()->appendError(error);
valid = false;
return;
}
......@@ -42,6 +43,7 @@ DatabasePrivate::DatabasePrivate(Database* db, QString const& pathToDatabase)
valid = false;
error.setType( Error::DatabaseError );
error.setDescription( ex.what() );
Akabei::ErrorQueue::instance()->appendError(error);
}
}
......
......@@ -25,6 +25,10 @@
#include <QFileInfo>
#include <QDir>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sqlite3.h>
namespace Akabei {
......@@ -63,9 +67,34 @@ void PlainRemoveOperation::run()
QMap<QString, QString> backup = d->package->backupFiles();
foreach (const QString &file, d->package->retrieveFiles()) {
struct stat buffer;
int status = lstat(file.toUtf8().data(), &buffer);
if (status == -1) {
qDebug() << "Does the file exist?!";
}
if (S_ISDIR(buffer.st_mode)) {
qDebug() << "is dir" << file;
QDir dir(file);
if (dir.count() > 0) {
++idx;
continue;
} else {
QDir dir;
if (!dir.rmdir(file) && !processingOptions().testFlag(Akabei::Force)) {
QString translated = QObject::tr("Removing %1 failed!").arg(file);
setErrors(Error::List() << Error(Error::UnknownError, translated, this));
setFinished(false);
}
setProgress((++idx * 100) / filesSize);
continue;
} //TODO: Else check the db if any other package owns it!!!
}
/* It's a directory: does nothing */
if ((file.endsWith('/') && !QFileInfo(file).isSymLink()) || (!processingOptions().testFlag(Akabei::RemoveConfigs) && backup.contains(file))) {
akabeiDebug() << "You know what?" << file << "is a directory!";
if (!processingOptions().testFlag(Akabei::RemoveConfigs) && backup.contains(file)) {
akabeiDebug() << "Don't remove the backup file";
++idx;
continue;
}
......
......@@ -24,6 +24,10 @@
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <QtConcurrentRun>
static uint m_pid = 0;
......@@ -51,9 +55,8 @@ bool FilesystemHelper::remove(const QString &file)
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
return QFile::remove(file);
} else {
qDebug() << "No authorization" << auth;
}
qDebug() << "No authorization" << auth;
return false;
}
......@@ -64,9 +67,8 @@ bool FilesystemHelper::copy(const QString &source, const QString &destination)
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
return QFile::copy(source, destination);
} else {
qDebug() << "No authorization" << auth;
}
qDebug() << "No authorization" << auth;
return false;
}
......@@ -76,11 +78,36 @@ void FilesystemHelper::removeFiles(const QStringList& files, int processingOptio
int filesSize = files.size();
QStringList errors;
foreach (QString file, files) {
if (file.endsWith('/') && !QFileInfo(file).isSymLink()) {
++idx;
// It's a directory (or something else we don't want to remove :D)
continue;
struct stat buffer;
int status = lstat(file.toUtf8().data(), &buffer);
if (status == -1) {
qDebug() << "Does the file exist?!";
}
if (S_ISDIR(buffer.st_mode)) {
qDebug() << "is dir" << file;
QDir dir(file);
if (dir.count() > 0) {
++idx;
continue;
} else {
QDir dir;
if (!dir.rmdir(file) && !((Akabei::ProcessingOptions) processingOptions).testFlag(Akabei::Force)) {
QString translated = QObject::tr("Removing %1 failed!").arg(file);
errors << translated;
}
emit removeFilesProgress((++idx * 100) / filesSize);
continue;
} //TODO: Else check the db if any other package owns it!!!
}
//if (S_ISLNK(buffer.st_mode)) {
// ++idx;
// // It's a directory (or something else we don't want to remove :D)
// continue;
//}
QFile f(file);
if (!f.remove() && !((Akabei::ProcessingOptions) processingOptions).testFlag(Akabei::Force)) {
......@@ -103,9 +130,8 @@ QByteArray FilesystemHelper::md5sumOfFile(const QString &file)
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
return Akabei::Helpers::md5sumOfFile(file);
} else {
qDebug() << "No authorization" << auth;
}
qDebug() << "No authorization" << auth;
return QByteArray();
}
......
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