mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07:00
Remove torrent temp folder when torrent is deleted
This commit is contained in:
parent
66b92f3bb4
commit
91a38193f5
3 changed files with 20 additions and 12 deletions
|
@ -1391,7 +1391,14 @@ bool Session::deleteTorrent(const QString &hash, bool deleteLocalFiles)
|
||||||
|
|
||||||
// Remove it from session
|
// Remove it from session
|
||||||
if (deleteLocalFiles) {
|
if (deleteLocalFiles) {
|
||||||
m_savePathsToRemove[torrent->hash()] = torrent->rootPath(true);
|
if (torrent->savePath(true) == torrentTempPath(torrent->hash())) {
|
||||||
|
m_savePathsToRemove[torrent->hash()] = torrent->savePath(true);
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
@ -3363,17 +3370,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)
|
||||||
|
|
|
@ -119,7 +119,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 = {
|
||||||
|
@ -180,12 +180,14 @@ 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)
|
||||||
{
|
{
|
||||||
|
if (path.isEmpty())
|
||||||
|
return;
|
||||||
#ifdef QBT_USES_QT5
|
#ifdef QBT_USES_QT5
|
||||||
QDir(dirName).removeRecursively();
|
QDir(path).removeRecursively();
|
||||||
#else
|
#else
|
||||||
QDir dir(dirName);
|
QDir dir(path);
|
||||||
|
|
||||||
if (!dir.exists()) return;
|
if (!dir.exists()) return;
|
||||||
|
|
||||||
|
@ -198,7 +200,7 @@ void Utils::Fs::removeDirRecursive(const QString& dirName)
|
||||||
else forceRemove(info.absoluteFilePath());
|
else forceRemove(info.absoluteFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
dir.rmdir(dirName);
|
dir.rmdir(path);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,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);
|
||||||
|
|
||||||
/* Ported from Qt4 to drop dependency on QtGui */
|
/* Ported from Qt4 to drop dependency on QtGui */
|
||||||
QString QDesktopServicesDataLocation();
|
QString QDesktopServicesDataLocation();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue