diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 5c191cb63..8d43eee20 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -771,10 +771,12 @@ void Bittorrent::deleteTorrent(QString hash, bool delete_local_files) { } const QString &fileName = h.name(); // Remove it from session - if(delete_local_files) + if(delete_local_files) { + savePathsToRemove[hash] = h.save_path(); s->remove_torrent(h.get_torrent_handle(), session::delete_files); - else + } else { s->remove_torrent(h.get_torrent_handle()); + } // Remove it from torrent backup directory QDir torrentBackup(misc::BTBackupLocation()); QStringList filters; @@ -2070,6 +2072,41 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { } } } + else if (torrent_deleted_alert* p = dynamic_cast(a.get())) { + qDebug("A torrent was deleted from the hard disk, attempting to remove the root folder too..."); + QString hash; +#if LIBTORRENT_VERSION_MINOR > 14 + hash = misc::toQString(p->info_hash); + +#else + // Unfortunately libtorrent v0.14 does not provide the hash, + // only the torrent handle that is often invalid when it arrives + try { + if(p->handle.is_valid()) { + hash = misc::toQString(p->handle.info_hash()); + } + }catch(std::exception){} +#endif + if(!hash.isEmpty()) { + if(savePathsToRemove.contains(hash)) { + misc::removeEmptyTree(savePathsToRemove.take(hash)); + } + } else { + // XXX: Fallback + QStringList hashes_deleted; + foreach(const QString& key, savePathsToRemove.keys()) { + // Attempt to delete + misc::removeEmptyTree(savePathsToRemove[key]); + if(!QDir(savePathsToRemove[key]).exists()) { + hashes_deleted << key; + } + } + // Clean up + foreach(const QString& key, hashes_deleted) { + savePathsToRemove.remove(key); + } + } + } else if (storage_moved_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); if(h.is_valid()) { diff --git a/src/bittorrent.h b/src/bittorrent.h index b3e5e1de5..1b98b4558 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -226,6 +226,7 @@ private: QPointer bd_scheduler; QMap savepath_fromurl; QHash > trackersInfos; + QHash savePathsToRemove; QStringList torrentsToPausedAfterChecking; QTimer resumeDataTimer; // Ratio diff --git a/src/src.pro b/src/src.pro index 74e9222e1..98f01897d 100644 --- a/src/src.pro +++ b/src/src.pro @@ -3,7 +3,7 @@ LANG_PATH = lang ICONS_PATH = Icons # Set the following variable to 1 to enable debug -DEBUG_MODE = 0 +DEBUG_MODE = 1 # Global TEMPLATE = app