From 8f5bd2bc9fb8c788cc37ea9fa0109f8583785c15 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 17 Jul 2010 21:35:00 +0000 Subject: [PATCH] Fix other temp path issues --- src/bittorrent.cpp | 13 ++++++++----- src/qtorrenthandle.cpp | 2 ++ src/torrentpersistentdata.h | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 99c3f2f61..f868eb8c4 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1699,6 +1699,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { h.move_storage(getSavePath(h.hash())); } } else { + qDebug("Enabling default temp path..."); // Moving all downloading torrents to temporary save path std::vector torrents = getTorrents(); std::vector::iterator torrentIT; @@ -1707,11 +1708,12 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { if(!h.is_valid()) continue; if(!h.is_seed()) { QString root_folder = TorrentPersistentData::getRootFolder(h.hash()); - QString torrent_tmp_path = defaultTempPath.replace("\\", "/"); + QString torrent_tmp_path = temppath.replace("\\", "/"); if(!root_folder.isEmpty()) { if(!torrent_tmp_path.endsWith("/")) torrent_tmp_path += "/"; torrent_tmp_path += root_folder; } + qDebug("Moving torrent to its temp save path: %s", qPrintable(torrent_tmp_path)); h.move_storage(torrent_tmp_path); } } @@ -2118,13 +2120,14 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { QTorrentHandle h(p->handle); if(h.is_valid()) { // Attempt to remove old folder if empty - const QString& old_save_path = TorrentPersistentData::getSavePath(h.hash()); + const QString& old_save_path = TorrentPersistentData::getPreviousPath(h.hash()); const QString new_save_path = QString::fromLocal8Bit(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)); - if(old_save_path != defaultSavePath && old_save_path != defaultTempPath) - QDir().rmdir(old_save_path); - if(new_save_path != defaultTempPath) + QDir old_save_dir(old_save_path); + if(old_save_dir != QDir(defaultSavePath) && old_save_dir != QDir(defaultTempPath)) + misc::removeEmptyTree(old_save_path); + if(!new_save_path.startsWith(defaultTempPath)) TorrentPersistentData::saveSavePath(h.hash(), new_save_path); emit savePathChanged(h); //h.force_recheck(); diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index bddafa49b..8aaa08994 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -599,6 +599,8 @@ void QTorrentHandle::force_recheck() const { void QTorrentHandle::move_storage(QString new_path) const { Q_ASSERT(h.is_valid()); + if(QDir(save_path()) == QDir(new_path)) return; + TorrentPersistentData::setPreviousSavePath(hash(), save_path()); h.move_storage(new_path.toLocal8Bit().constData()); } diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index 8f00b2288..8491328af 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -242,6 +242,22 @@ public: QHash data = all_data[hash].toHash(); return data.value("root_folder", QString()).toString(); } + + static void setPreviousSavePath(QString hash, QString previous_path) { + QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); + QHash all_data = settings.value("torrents", QHash()).toHash(); + QHash data = all_data[hash].toHash(); + data.insert("previous_path", previous_path); + all_data[hash] = data; + settings.setValue("torrents", all_data); + } + + static QString getPreviousPath(QString hash) { + QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); + QHash all_data = settings.value("torrents", QHash()).toHash(); + QHash data = all_data[hash].toHash(); + return data.value("previous_path", QString()).toString(); + } static void saveSeedDate(const QTorrentHandle &h) { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));