From 801b389ce7dc55197a97ccf857d172be83bb0771 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sun, 19 Feb 2023 13:11:22 -0500 Subject: [PATCH] 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. --- src/ytdl_sub/utils/file_handler.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ytdl_sub/utils/file_handler.py b/src/ytdl_sub/utils/file_handler.py index 6a3dc6c9..4cbf41f6 100644 --- a/src/ytdl_sub/utils/file_handler.py +++ b/src/ytdl_sub/utils/file_handler.py @@ -365,11 +365,8 @@ class FileHandler: # 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]):