From 850556fdfad4425f92094b859e47de7095db072c Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Sat, 23 Apr 2016 19:34:01 +0300 Subject: [PATCH 1/2] Use unique temp directories Save torrent in temp_path/ directory. Closes #5154. --- src/base/bittorrent/session.cpp | 7 ++++++- src/base/bittorrent/session.h | 1 + src/base/bittorrent/torrenthandle.cpp | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 267109e49..c7d5b571a 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -331,6 +331,11 @@ QString Session::tempPath() const return m_tempPath; } +QString Session::torrentTempPath(const InfoHash &hash) const +{ + return m_tempPath + QString(hash) + "/"; +} + bool Session::isValidCategoryName(const QString &name) { QRegExp re(R"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"); @@ -1398,7 +1403,7 @@ bool Session::findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) c bool found = findInDir(savePath, torrentInfo); if (!found && isTempPathEnabled()) { - savePath = m_tempPath; + savePath = torrentTempPath(torrentInfo.hash()); found = findInDir(savePath, torrentInfo); } diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 4b9e30a1c..705893185 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -185,6 +185,7 @@ namespace BitTorrent void setTempPath(QString path); bool isTempPathEnabled() const; void setTempPathEnabled(bool enabled); + QString torrentTempPath(const InfoHash &hash) const; static bool isValidCategoryName(const QString &name); // returns category itself and all top level categories diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index db006aefe..d0f4fd84a 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1392,7 +1392,7 @@ void TorrentHandle::handleStorageMovedAlert(libtorrent::storage_moved_alert *p) // Attempt to remove old folder if empty QDir oldSaveDir(Utils::Fs::fromNativePath(m_oldPath)); - if ((oldSaveDir != QDir(m_session->defaultSavePath())) && (oldSaveDir != QDir(m_session->tempPath()))) { + if (oldSaveDir != QDir(m_session->defaultSavePath())) { qDebug("Attempting to remove %s", qPrintable(m_oldPath)); QDir().rmpath(m_oldPath); } @@ -1778,7 +1778,7 @@ void TorrentHandle::adjustActualSavePath_impl() } else { // Moving all downloading torrents to temporary save path - path = m_session->tempPath(); + path = m_session->torrentTempPath(hash()); qDebug() << "Moving torrent to its temp save path:" << path; } From b8c703b8b0d8d62b38df7111d723fd19ceb87384 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Sat, 23 Apr 2016 21:01:56 +0300 Subject: [PATCH 2/2] Use truncated torrent hash in temp path --- src/base/bittorrent/infohash.cpp | 1 - src/base/bittorrent/session.cpp | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/infohash.cpp b/src/base/bittorrent/infohash.cpp index b492fcb44..293e650fe 100644 --- a/src/base/bittorrent/infohash.cpp +++ b/src/base/bittorrent/infohash.cpp @@ -68,7 +68,6 @@ bool InfoHash::isValid() const return m_valid; } - InfoHash::operator libtorrent::sha1_hash() const { return m_nativeHash; diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index c7d5b571a..831af3fb4 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -333,7 +333,9 @@ QString Session::tempPath() const QString Session::torrentTempPath(const InfoHash &hash) const { - return m_tempPath + QString(hash) + "/"; + return m_tempPath + + static_cast(hash).left(7) + + "/"; } bool Session::isValidCategoryName(const QString &name)