From 69df95e0e9cb95762f72cf352466d4b5ad242903 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 20 Feb 2023 00:06:48 -0500 Subject: [PATCH] [BACKEND] Always perform copy/delete on OSError (#446) * Always perform copy/delete on OSError Extends the fix in #400 to handle all potential OSError errno values and attempt a copy/delete in all cases. For example, a combination cross-device move and a permissions change would throw errno 1 instead of errno 18, which wasn't caught here. Instead of messing with individual errno numbers, just always attempt a copy/delete and let those throw their own exceptions if they don't work either. * Remove unused os_error_exc variable --- src/ytdl_sub/utils/file_handler.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/ytdl_sub/utils/file_handler.py b/src/ytdl_sub/utils/file_handler.py index 6a3dc6c9..fdc8eabd 100644 --- a/src/ytdl_sub/utils/file_handler.py +++ b/src/ytdl_sub/utils/file_handler.py @@ -361,15 +361,12 @@ class FileHandler: """ try: shutil.move(src=src_file_path, dst=dst_file_path) - except OSError as os_error_exc: + except OSError: # Invalid cross-device link # Can happen from using os.rename under the hood, which requires the two file on the # same filesystem. Work around it by copying and deleting the file - if os_error_exc.errno == 18: - cls.copy(src_file_path, dst_file_path) - cls.delete(src_file_path) - else: - raise + cls.copy(src_file_path, dst_file_path) + cls.delete(src_file_path) @classmethod def delete(cls, file_path: Union[str, Path]):