From f02ac2eaef33c3bc5d1152c715c04db2433a9c31 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 21 Aug 2023 18:05:17 +0800 Subject: [PATCH] fix --- app/modules/qbittorrent/__init__.py | 8 ++++++++ app/modules/transmission/__init__.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index 4c4ab689..fbca0e6f 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -1,3 +1,4 @@ +import shutil from pathlib import Path from typing import Set, Tuple, Optional, Union, List @@ -12,6 +13,7 @@ from app.modules.qbittorrent.qbittorrent import Qbittorrent from app.schemas import TransferInfo, TransferTorrent, DownloadingTorrent from app.schemas.types import TorrentStatus from app.utils.string import StringUtils +from app.utils.system import SystemUtils class QbittorrentModule(_ModuleBase): @@ -164,6 +166,12 @@ class QbittorrentModule(_ModuleBase): if settings.TRANSFER_TYPE == "move": if self.remove_torrents(hashs): logger.info(f"移动模式删除种子成功:{hashs} ") + # 删除残留文件 + if transinfo.path and transinfo.path.exists(): + files = SystemUtils.list_files_with_extensions(transinfo.path, settings.RMT_MEDIAEXT) + if not files: + logger.warn(f"删除残留文件夹:{transinfo.path}") + shutil.rmtree(transinfo.path, ignore_errors=True) def remove_torrents(self, hashs: Union[str, list]) -> bool: """ diff --git a/app/modules/transmission/__init__.py b/app/modules/transmission/__init__.py index 01aa7ebd..91bf062e 100644 --- a/app/modules/transmission/__init__.py +++ b/app/modules/transmission/__init__.py @@ -1,3 +1,4 @@ +import shutil from pathlib import Path from typing import Set, Tuple, Optional, Union, List @@ -12,6 +13,7 @@ from app.modules.transmission.transmission import Transmission from app.schemas import TransferInfo, TransferTorrent, DownloadingTorrent from app.schemas.types import TorrentStatus from app.utils.string import StringUtils +from app.utils.system import SystemUtils class TransmissionModule(_ModuleBase): @@ -148,6 +150,12 @@ class TransmissionModule(_ModuleBase): if settings.TRANSFER_TYPE == "move": if self.remove_torrents(hashs): logger.info(f"移动模式删除种子成功:{hashs} ") + # 删除残留文件 + if transinfo.path and transinfo.path.exists(): + files = SystemUtils.list_files_with_extensions(transinfo.path, settings.RMT_MEDIAEXT) + if not files: + logger.warn(f"删除残留文件夹:{transinfo.path}") + shutil.rmtree(transinfo.path, ignore_errors=True) def remove_torrents(self, hashs: Union[str, list]) -> bool: """