summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2013-06-20 18:55:27 +0800
committerRussell Keith-Magee <russell@keith-magee.com>2013-06-20 18:55:27 +0800
commit18e79f1425fa87f2f38df25c65203ec4d311f499 (patch)
tree8060a3ed343f8bf27373e4c2d79c0de224424843 /django
parent3671e7e3e0603ed8908eb1328a82396e22b9224c (diff)
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.
Diffstat (limited to 'django')
-rw-r--r--django/core/files/move.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/django/core/files/move.py b/django/core/files/move.py
index 4519dedf97..4bd739b4c4 100644
--- a/django/core/files/move.py
+++ b/django/core/files/move.py
@@ -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: