Browse Source

When removing torrents from hard disk, also remove root folders

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
f9684d662d
  1. 41
      src/bittorrent.cpp
  2. 1
      src/bittorrent.h
  3. 2
      src/src.pro

41
src/bittorrent.cpp

@ -771,10 +771,12 @@ void Bittorrent::deleteTorrent(QString hash, bool delete_local_files) { @@ -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) { @@ -2070,6 +2072,41 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
}
}
}
else if (torrent_deleted_alert* p = dynamic_cast<torrent_deleted_alert*>(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<storage_moved_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(h.is_valid()) {

1
src/bittorrent.h

@ -226,6 +226,7 @@ private: @@ -226,6 +226,7 @@ private:
QPointer<BandwidthScheduler> bd_scheduler;
QMap<QUrl, QString> savepath_fromurl;
QHash<QString, QHash<QString, TrackerInfos> > trackersInfos;
QHash<QString, QString> savePathsToRemove;
QStringList torrentsToPausedAfterChecking;
QTimer resumeDataTimer;
// Ratio

2
src/src.pro

@ -3,7 +3,7 @@ LANG_PATH = lang @@ -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

Loading…
Cancel
Save