From f243b8535a9d7e6d6e014483deb5684ffaf21e0e Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 10 Apr 2010 15:03:16 +0000 Subject: [PATCH] - BUGFIX: Remove old folder when moving a torrent - BUGFIX: Improved reliability of torrent moving --- Changelog | 2 ++ src/bittorrent.cpp | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 78c87cc9a..b847e9332 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,8 @@ * Unreleased - Christophe Dumez - v2.2.6 - BUGFIX: Announce to all trackers at once - BUGFIX: Added support for single-thread boost + - BUGFIX: Remove old folder when moving a torrent + - BUGFIX: Improved reliability of torrent moving * Wed Apr 07 2010 - Christophe Dumez - v2.2.5 - BUGFIX: Fix crash when adding a new torrent label diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index d1aa97939..e33d8e0a2 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1652,12 +1652,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { } else { new_save_path = old_dir.absoluteFilePath(new_label); } - TorrentPersistentData::saveSavePath(h.hash(), new_save_path); if(move_storage) { // Move storage h.move_storage(new_save_path); } - emit savePathChanged(h); } void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle h) { @@ -1669,12 +1667,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { const QDir old_dir(old_save_path); if(old_dir.dirName() != label) { const QString &new_save_path = old_dir.absoluteFilePath(label); - TorrentPersistentData::saveSavePath(h.hash(), new_save_path); if(old_dir == QDir(h.save_path())) { // Move storage h.move_storage(new_save_path); } - emit savePathChanged(h); } } @@ -1965,8 +1961,17 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { } else if (storage_moved_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); - if(h.is_valid()) + if(h.is_valid()) { + // Attempt to remove old folder if empty + const QString& old_save_path = TorrentPersistentData::getSavePath(h.hash()); + const QString new_save_path = QString(p->path.c_str()); + qDebug("Torrent moved from %s to %s", qPrintable(old_save_path), qPrintable(new_save_path)); + qDebug("Attempting to remove %s", qPrintable(old_save_path)); + QDir().rmpath(old_save_path); + TorrentPersistentData::saveSavePath(h.hash(), new_save_path); + emit savePathChanged(h); h.force_recheck(); //XXX: Required by libtorrent for now + } } else if (metadata_received_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle);