1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-12 07:48:04 +00:00

Merge pull request #6694 from glassez/remove-temp

Remove torrent temp folder when it becomes unneeded
This commit is contained in:
Vladimir Golovnev 2017-04-29 11:44:15 +03:00 committed by GitHub
commit 70f1153413
4 changed files with 21 additions and 12 deletions

View File

@ -1405,9 +1405,14 @@ bool Session::deleteTorrent(const QString &hash, bool deleteLocalFiles)
// Remove it from session // Remove it from session
if (deleteLocalFiles) { if (deleteLocalFiles) {
QString rootPath = torrent->rootPath(true); if (torrent->savePath(true) == torrentTempPath(torrent->hash())) {
if (!rootPath.isEmpty()) m_savePathsToRemove[torrent->hash()] = torrent->savePath(true);
m_savePathsToRemove[torrent->hash()] = rootPath; }
else {
QString rootPath = torrent->rootPath(true);
if (!rootPath.isEmpty())
m_savePathsToRemove[torrent->hash()] = rootPath;
}
m_nativeSession->remove_torrent(torrent->nativeHandle(), libt::session::delete_files); m_nativeSession->remove_torrent(torrent->nativeHandle(), libt::session::delete_files);
} }
else { else {
@ -3441,17 +3446,16 @@ void Session::handleTorrentRemovedAlert(libt::torrent_removed_alert *p)
void Session::handleTorrentDeletedAlert(libt::torrent_deleted_alert *p) void Session::handleTorrentDeletedAlert(libt::torrent_deleted_alert *p)
{ {
m_savePathsToRemove.remove(p->info_hash); const QString path = m_savePathsToRemove.take(p->info_hash);
if (path == torrentTempPath(p->info_hash))
Utils::Fs::smartRemoveEmptyFolderTree(path);
} }
void Session::handleTorrentDeleteFailedAlert(libt::torrent_delete_failed_alert *p) void Session::handleTorrentDeleteFailedAlert(libt::torrent_delete_failed_alert *p)
{ {
// libtorrent won't delete the directory if it contains files not listed in the torrent, // libtorrent won't delete the directory if it contains files not listed in the torrent,
// so we remove the directory ourselves // so we remove the directory ourselves
if (m_savePathsToRemove.contains(p->info_hash)) { Utils::Fs::smartRemoveEmptyFolderTree(m_savePathsToRemove.take(p->info_hash));
QString path = m_savePathsToRemove.take(p->info_hash);
Utils::Fs::smartRemoveEmptyFolderTree(path);
}
} }
void Session::handleMetadataReceivedAlert(libt::metadata_received_alert *p) void Session::handleMetadataReceivedAlert(libt::metadata_received_alert *p)

View File

@ -1358,6 +1358,10 @@ void TorrentHandle::handleStorageMovedAlert(libtorrent::storage_moved_alert *p)
} }
qDebug("Torrent is successfully moved from %s to %s", qPrintable(m_oldPath), qPrintable(m_newPath)); qDebug("Torrent is successfully moved from %s to %s", qPrintable(m_oldPath), qPrintable(m_newPath));
if (m_oldPath == m_session->torrentTempPath(hash())) {
qDebug() << "Removing torrent temp folder:" << m_oldPath;
Utils::Fs::smartRemoveEmptyFolderTree(m_oldPath);
}
updateStatus(); updateStatus();
m_newPath.clear(); m_newPath.clear();

View File

@ -100,7 +100,7 @@ QString Utils::Fs::folderName(const QString& file_path)
*/ */
bool Utils::Fs::smartRemoveEmptyFolderTree(const QString& path) bool Utils::Fs::smartRemoveEmptyFolderTree(const QString& path)
{ {
if (!QDir(path).exists()) if (path.isEmpty() || !QDir(path).exists())
return false; return false;
static const QStringList deleteFilesList = { static const QStringList deleteFilesList = {
@ -161,9 +161,10 @@ bool Utils::Fs::forceRemove(const QString& file_path)
* Removes directory and its content recursively. * Removes directory and its content recursively.
* *
*/ */
void Utils::Fs::removeDirRecursive(const QString& dirName) void Utils::Fs::removeDirRecursive(const QString &path)
{ {
QDir(dirName).removeRecursively(); if (!path.isEmpty())
QDir(path).removeRecursively();
} }
/** /**

View File

@ -59,7 +59,7 @@ namespace Utils
bool smartRemoveEmptyFolderTree(const QString& path); bool smartRemoveEmptyFolderTree(const QString& path);
bool forceRemove(const QString& file_path); bool forceRemove(const QString& file_path);
void removeDirRecursive(const QString& dirName); void removeDirRecursive(const QString& path);
QString tempPath(); QString tempPath();
} }