fix: retry file deletion to allow libtorrent to release handles

This commit is contained in:
Vxrtrauter
2026-03-11 00:57:48 +01:00
parent f34d02d3d0
commit c4685dc2de
+18 -15
View File
@@ -989,7 +989,6 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
return return
magnet_link = list(state.active_downloads.keys())[row] magnet_link = list(state.active_downloads.keys())[row]
magnetdl = state.active_downloads[magnet_link] magnetdl = state.active_downloads[magnet_link]
try: try:
status = magnetdl.status() status = magnetdl.status()
save_path = status.save_path save_path = status.save_path
@@ -1000,9 +999,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
state.active_downloads.pop(magnet_link, None) state.active_downloads.pop(magnet_link, None)
remove_download_log(magnet_link) remove_download_log(magnet_link)
return return
download_path = os.path.join(save_path, torrent_name) download_path = os.path.join(save_path, torrent_name)
confirm = QMessageBox.question( confirm = QMessageBox.question(
self, "Delete Files", self, "Delete Files",
f"Are you sure you want to delete the downloaded files of '{torrent_name}'? This action cannot be undone.", f"Are you sure you want to delete the downloaded files of '{torrent_name}'? This action cannot be undone.",
@@ -1012,23 +1009,29 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
with state.downloads_lock: with state.downloads_lock:
state.active_downloads.pop(magnet_link, None) state.active_downloads.pop(magnet_link, None)
remove_download_log(magnet_link) remove_download_log(magnet_link)
if state.dl_session: if state.dl_session:
try: try:
state.dl_session.remove_torrent(magnetdl) state.dl_session.remove_torrent(magnetdl)
time.sleep(0.5)
except Exception: except Exception:
pass pass
if download_path and os.path.exists(download_path): if download_path and os.path.exists(download_path):
try: import shutil
if os.path.isfile(download_path): last_error = None
os.remove(download_path) for attempt in range(3):
try:
if os.path.isfile(download_path):
os.remove(download_path)
else:
shutil.rmtree(download_path)
consoleLog(f"Deleted files for: {torrent_name}", True) consoleLog(f"Deleted files for: {torrent_name}", True)
else: last_error = None
import shutil break
shutil.rmtree(download_path) except Exception as e:
consoleLog(f"Deleted files for: {torrent_name}", True) last_error = e
except Exception as e: if attempt < 2:
consoleLog(f"Error deleting files: {e}", True) time.sleep(0.5)
if last_error:
consoleLog(f"Error deleting files: {last_error}", True)
else: else:
consoleLog(f"Removed entry (files not found): {torrent_name}", True) consoleLog(f"Removed entry (files not found): {torrent_name}", True)