diff --git a/Changelog b/Changelog index b5882ca6f..793d091b6 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,7 @@ - BUGFIX: Fix priority up/down for multiple torrents at the same time (closes #692184) - BUGFIX: Make sure the number of torrents is properly set on startup (closes #694135) - BUGFIX: Fix scan directories saving (closes #694768) + - BUGFIX: Remove empty folders on torrent soft deletion (closes #695174) - BUGFIX: Make sure the main window has focus on startup * Sun Dec 19 2010 - Christophe Dumez - v2.5.2 diff --git a/src/misc.cpp b/src/misc.cpp index ff0b5825e..bf997d501 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -557,19 +557,6 @@ bool misc::isPreviewable(QString extension){ return false; } -bool misc::removeEmptyTree(QString path) { - QDir dir(path); - foreach(const QString &child, dir.entryList(QDir::AllDirs)) { - if(child == "." || child == "..") continue; - return removeEmptyTree(dir.absoluteFilePath(child)); - } - const QString dir_name = dir.dirName(); - if(dir.cdUp()) { - return dir.rmdir(dir_name); - } - return false; -} - QString misc::bcLinkToMagnet(QString bc_link) { QByteArray raw_bc = bc_link.toUtf8(); raw_bc = raw_bc.mid(8); // skip bc://bt/ @@ -759,3 +746,9 @@ bool misc::isValidTorrentFile(const QString &torrent_path) { } return true; } + +QString misc::branchPath(QString file_path) +{ + file_path.replace("\\", "/"); + return file_path.left(file_path.lastIndexOf('/')); +} diff --git a/src/misc.h b/src/misc.h index ab5c5c2de..9ed57ebcf 100644 --- a/src/misc.h +++ b/src/misc.h @@ -149,7 +149,7 @@ public: // value must be given in bytes static QString friendlyUnit(double val); static bool isPreviewable(QString extension); - static bool removeEmptyTree(QString path); + static QString branchPath(QString file_path); static QString magnetUriToName(QString magnet_uri); static QString magnetUriToHash(QString magnet_uri); static QString bcLinkToMagnet(QString bc_link); diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index a887fd877..db6eaac74 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -631,7 +631,8 @@ void PropertiesWidget::renameSelectedFile() { // Remove old folder const QDir old_folder(h.save_path()+"/"+old_path); int timeout = 10; - while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) { + while(!QDir().rmpath(old_folder.absolutePath()) && timeout > 0) { + // XXX: We should not sleep here (freezes the UI for 1 second) SleeperThread::msleep(100); --timeout; } diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 30f657ee3..0c61a5201 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -277,7 +277,7 @@ void QBtSession::configureSession() { int i = 0; foreach (const QString &dir, scan_dirs) { qDebug() << "Adding scan dir" << dir << downloadInDirList.at(i); - ScanFoldersModel::PathStatus ret = m_scanFolders->addPath(dir, downloadInDirList.at(i)); + m_scanFolders->addPath(dir, downloadInDirList.at(i)); ++i; } // * Export Dir @@ -736,6 +736,9 @@ void QBtSession::deleteTorrent(QString hash, bool delete_local_files) { foreach(const QString &uneeded_file, uneeded_files) { qDebug("Removing uneeded file: %s", qPrintable(uneeded_file)); misc::safeRemove(uneeded_file); + const QString parent_folder = misc::branchPath(uneeded_file); + qDebug("Attempt to remove parent folder (if empty): %s", qPrintable(parent_folder)); + QDir().rmpath(parent_folder); } } // Remove it from torrent backup directory @@ -2107,14 +2110,14 @@ void QBtSession::readAlerts() { #endif if(!hash.isEmpty()) { if(savePathsToRemove.contains(hash)) { - misc::removeEmptyTree(savePathsToRemove.take(hash)); + QDir().rmpath(savePathsToRemove.take(hash)); } } else { // XXX: Fallback QStringList hashes_deleted; foreach(const QString& key, savePathsToRemove.keys()) { // Attempt to delete - misc::removeEmptyTree(savePathsToRemove[key]); + QDir().rmpath(savePathsToRemove[key]); if(!QDir(savePathsToRemove[key]).exists()) { hashes_deleted << key; } @@ -2135,7 +2138,7 @@ void QBtSession::readAlerts() { QDir old_save_dir(old_save_path); if(old_save_dir != QDir(defaultSavePath) && old_save_dir != QDir(defaultTempPath)) { qDebug("Attempting to remove %s", qPrintable(old_save_path)); - misc::removeEmptyTree(old_save_path); + QDir().rmpath(old_save_path); } if(defaultTempPath.isEmpty() || !new_save_path.startsWith(defaultTempPath)) { qDebug("Storage has been moved, updating save path to %s", qPrintable(new_save_path));