Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #8900: Added errno=13 (permission denied) to the class of ignor…

…ed 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
  • Loading branch information...
commit 50d3ebf72af0baedcc4c288dfd2d8a5a18bd6f5e 1 parent a9931e5
@kmtracey kmtracey authored
Showing with 9 additions and 10 deletions.
  1. +9 −10 django/core/files/move.py
View
19 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
Please sign in to comment.
Something went wrong with that request. Please try again.