Skip to content

Commit

Permalink
fix(DTrashManager): clear trash behavior not correct
Browse files Browse the repository at this point in the history
Change-Id: I65bcee631da8d8db3089370beb28144d20c66ef2
  • Loading branch information
BLumia committed Jul 9, 2018
1 parent 79d7283 commit 1242bf6
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions src/util/dtrashmanager_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ class DTrashManagerPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate
DTrashManagerPrivate(DTrashManager *q_ptr)
: DObjectPrivate(q_ptr) {}

static bool removeFileOrDir(const QString &path);
static bool removeFromIterator(QDirIterator &iter);

D_DECLARE_PUBLIC(DTrashManager)
};

Expand All @@ -175,28 +178,14 @@ bool DTrashManager::trashIsEmpty() const
bool DTrashManager::cleanTrash()
{
QDirIterator iterator_info(TRASH_INFO_PATH,
// QStringList() << "*.trashinfo",
QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden);

bool ok = true;

while (iterator_info.hasNext()) {
if (!QFile::remove(iterator_info.next())) {
ok = false;
}
}

QDirIterator iterator_files(TRASH_FILES_PATH,
QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden,
QDirIterator::Subdirectories);

while (iterator_files.hasNext()) {
if (!QFile::remove(iterator_files.next())) {
ok = false;
}
}

return ok;
return DTrashManagerPrivate::removeFromIterator(iterator_info) &&
DTrashManagerPrivate::removeFromIterator(iterator_files);
}

bool DTrashManager::moveToTrash(const QString &filePath, bool followSymlink)
Expand Down Expand Up @@ -245,4 +234,28 @@ DTrashManager::DTrashManager()

}

bool DTrashManagerPrivate::removeFileOrDir(const QString &path)
{
QFileInfo fileInfo(path);
if (fileInfo.isDir()) {
QDir dir(path);
return dir.removeRecursively();
} else {
return QFile::remove(path);
}
}

bool DTrashManagerPrivate::removeFromIterator(QDirIterator &iter)
{
bool ok = true;
while (iter.hasNext()) {
QString nextPath = iter.next();
// qDebug() << iter.fileName() << iterator_info.filePath();
if (!DTrashManagerPrivate::removeFileOrDir(nextPath)) {
ok = false;
}
}
return ok;
}

DWIDGET_END_NAMESPACE

0 comments on commit 1242bf6

Please sign in to comment.