mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #20486 -- Ensure that file_move_safe raises an error if the destination already exists.
Thanks to kux for the report, and Russ Webber for the patch.
This commit is contained in:
@@ -51,6 +51,10 @@ def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_ove
|
||||
return
|
||||
|
||||
try:
|
||||
# If the destination file exists and allow_overwrite is False then raise an IOError
|
||||
if not allow_overwrite and os.access(new_file_name, os.F_OK):
|
||||
raise IOError("Destination file %s exists and allow_overwrite is False" % new_file_name)
|
||||
|
||||
os.rename(old_file_name, new_file_name)
|
||||
return
|
||||
except OSError:
|
||||
|
||||
Reference in New Issue
Block a user