1
0
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:
Russell Keith-Magee
2013-06-20 18:55:27 +08:00
parent 3671e7e3e0
commit 18e79f1425
3 changed files with 19 additions and 0 deletions

View File

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