summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorDerrick Jackson <derrick_jackson@saa.senate.gov>2017-05-10 11:29:12 -0400
committerTim Graham <timograham@gmail.com>2017-05-31 14:52:40 -0400
commit789c290150a0a5e7312e152df281dbcaf4ec174e (patch)
tree8c1086d41f6c8761476f4f9a8aa7717ef7e45f4c /django
parent2ec56bb78237ebf58494d7a7f3262482399f0be6 (diff)
Fixed #28170 -- Fixed file_move_safe() crash when moving files to a CIFS mount.
Diffstat (limited to 'django')
-rw-r--r--django/core/files/move.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/django/core/files/move.py b/django/core/files/move.py
index 23491d6573..bf0f1fe4e8 100644
--- a/django/core/files/move.py
+++ b/django/core/files/move.py
@@ -5,6 +5,7 @@ Move a file in the safest way possible::
>>> file_move_safe("/tmp/old_file", "/tmp/new_file")
"""
+import errno
import os
from shutil import copystat
@@ -66,7 +67,15 @@ def file_move_safe(old_file_name, new_file_name, chunk_size=1024 * 64, allow_ove
finally:
locks.unlock(fd)
os.close(fd)
- copystat(old_file_name, new_file_name)
+
+ try:
+ copystat(old_file_name, new_file_name)
+ except PermissionError as e:
+ # Certain filesystems (e.g. CIFS) fail to copy the file's metadata if
+ # the type of the destination filesystem isn't the same as the source
+ # filesystem; ignore that.
+ if e.errno != errno.EPERM:
+ raise
try:
os.remove(old_file_name)