[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
This commit is contained in:
Joshua M. Boniface 2023-02-20 00:06:48 -05:00 committed by GitHub
parent 3106861a42
commit 69df95e0e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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]):