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.
This commit is contained in:
Joshua M. Boniface 2023-02-19 13:11:22 -05:00
parent 3106861a42
commit 801b389ce7

View file

@ -365,11 +365,8 @@ class FileHandler:
# Invalid cross-device link # Invalid cross-device link
# Can happen from using os.rename under the hood, which requires the two file on the # 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 # 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.copy(src_file_path, dst_file_path)
cls.delete(src_file_path) cls.delete(src_file_path)
else:
raise
@classmethod @classmethod
def delete(cls, file_path: Union[str, Path]): def delete(cls, file_path: Union[str, Path]):