summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2009-04-05 04:48:11 +0000
committerKaren Tracey <kmtracey@gmail.com>2009-04-05 04:48:11 +0000
commit50d3ebf72af0baedcc4c288dfd2d8a5a18bd6f5e (patch)
tree31cb1542d10c5dc634f04da9f288fa483f1d823f
parenta9931e5655bcf792d436759017dad6544e3aeed2 (diff)
Fixed #8900: Added errno=13 (permission denied) to the class of ignored OSErrors when attempting to delete the old file in file_move_safe.
This error was seen on Windows with Pythons < 2.5. In the case where the error was seen, the old file is auto-deleted on close anyway by the Windows-specific NamedTemporaryFile support. No new test because the failure could be seen when running the file_uploads test with Python 2.3/2.4 on Windows. With this fix file_uploads runs clean in that environment. While in the neignborhood fixed up the docstrings to better match the reality of what the code does and what the function is named. r10396 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10397 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/files/move.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/django/core/files/move.py b/django/core/files/move.py
index 99b831ffc9..3349fc22e7 100644
--- a/django/core/files/move.py
+++ b/django/core/files/move.py
@@ -1,8 +1,8 @@
"""
Move a file in the safest way possible::
- >>> from django.core.files.move import file_move_save
- >>> file_move_save("/tmp/old_file", "/tmp/new_file")
+ >>> from django.core.files.move import file_move_safe
+ >>> file_move_safe("/tmp/old_file", "/tmp/new_file")
"""
import os
@@ -39,10 +39,8 @@ def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_ove
"""
Moves a file from one location to another in the safest way possible.
- First, try using ``shutils.move``, which is OS-dependent but doesn't break
- if moving across filesystems. Then, try ``os.rename``, which will break
- across filesystems. Finally, streams manually from one file to another in
- pure Python.
+ First, tries ``os.rename``, which is simple but will break across filesystems.
+ If that fails, streams manually from one file to another in pure Python.
If the destination file exists and ``allow_overwrite`` is ``False``, this
function will throw an ``IOError``.
@@ -82,8 +80,9 @@ def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_ove
try:
os.remove(old_file_name)
except OSError, e:
- # Certain operating systems (Cygwin and Windows)
- # fail when deleting opened files, ignore it
- if getattr(e, 'winerror', 0) != 32:
- # FIXME: should we also ignore errno 13?
+ # Certain operating systems (Cygwin and Windows)
+ # fail when deleting opened files, ignore it. (For the
+ # systems where this happens, temporary files will be auto-deleted
+ # on close anyway.)
+ if getattr(e, 'winerror', 0) != 32 and getattr(e, 'errno', 0) != 13:
raise