File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed
Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -529,6 +529,22 @@ def is_active(self) -> bool:
529529 return True
530530 return False
531531
532+ def delete_temp_files (self ) -> None :
533+ """
534+ Delete temporary files created during download
535+ """
536+ try :
537+ # Delete the partially downloaded file
538+ if self .filepath .exists ():
539+ self .filepath .unlink ()
540+ logging .info (f"Deleted partially downloaded file: { self .filepath } " )
541+
542+ # Delete the progress file
543+ if self .progress_file .exists ():
544+ self .progress_file .unlink ()
545+ logging .info (f"Deleted progress file: { self .progress_file } " )
546+ except Exception as e :
547+ logging .warning (f"Failed to delete temporary files: { str (e )} " )
532548
533549 def stop (self ) -> None :
534550 """
@@ -539,4 +555,8 @@ def stop(self) -> None:
539555
540556 self .should_stop = True
541557 if self .active_thread and self .active_thread .is_alive ():
542- self .active_thread .join (timeout = 10 )
558+ self .active_thread .join (timeout = 10 )
559+
560+ # Delete temporary files if download was cancelled by user
561+ if not self .download_complete :
562+ self .delete_temp_files ()
Original file line number Diff line number Diff line change @@ -294,7 +294,10 @@ def is_dir_writable(dirpath):
294294 )
295295 if download_obj .download_complete is False :
296296 import os
297- os .remove (self .constants .user_download_file + "/" + file_name )
297+ try :
298+ os .remove (self .constants .user_download_file + "/" + file_name )
299+ except :
300+ pass
298301 self .on_return_to_main_menu ()
299302 return
300303 self .on_return_to_main_menu ()
Original file line number Diff line number Diff line change @@ -275,7 +275,10 @@ def is_dir_writable(dirpath):
275275 )
276276 if download_obj .download_complete is False :
277277 import os
278- os .remove (self .constants .user_download_file + "/" + file_name )
278+ try :
279+ os .remove (self .constants .user_download_file + "/" + file_name )
280+ except :
281+ pass
279282 self .on_return_to_main_menu ()
280283 return
281284
You can’t perform that action at this time.
0 commit comments