Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.



git-svn-id: http://code.djangoproject.com/svn/django/trunk@10396 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit df7ffe616ad0f0bdd29aecca97462f567ee75fd8 1 parent 63143d5
Karen Tracey authored

Showing 1 changed file with 9 additions and 10 deletions. Show diff stats Hide diff stats

  1. 19  django/core/files/move.py
19  django/core/files/move.py
... ...
@@ -1,8 +1,8 @@
1 1
 """
2 2
 Move a file in the safest way possible::
3 3
 
4  
-    >>> from django.core.files.move import file_move_save
5  
-    >>> file_move_save("/tmp/old_file", "/tmp/new_file")
  4
+    >>> from django.core.files.move import file_move_safe
  5
+    >>> file_move_safe("/tmp/old_file", "/tmp/new_file")
6 6
 """
7 7
 
8 8
 import os
@@ -39,10 +39,8 @@ def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_ove
39 39
     """
40 40
     Moves a file from one location to another in the safest way possible.
41 41
 
42  
-    First, try using ``shutils.move``, which is OS-dependent but doesn't break
43  
-    if moving across filesystems. Then, try ``os.rename``, which will break
44  
-    across filesystems. Finally, streams manually from one file to another in
45  
-    pure Python.
  42
+    First, tries ``os.rename``, which is simple but will break across filesystems.
  43
+    If that fails, streams manually from one file to another in pure Python.
46 44
 
47 45
     If the destination file exists and ``allow_overwrite`` is ``False``, this
48 46
     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
82 80
     try:
83 81
         os.remove(old_file_name)
84 82
     except OSError, e:
85  
-        # Certain operating systems (Cygwin and Windows)
86  
-        # fail when deleting opened files, ignore it
87  
-        if getattr(e, 'winerror', 0) != 32:
88  
-            # FIXME: should we also ignore errno 13?
  83
+        # Certain operating systems (Cygwin and Windows) 
  84
+        # fail when deleting opened files, ignore it.  (For the 
  85
+        # systems where this happens, temporary files will be auto-deleted
  86
+        # on close anyway.)
  87
+        if getattr(e, 'winerror', 0) != 32 and getattr(e, 'errno', 0) != 13:
89 88
             raise

0 notes on commit df7ffe6

Please sign in to comment.
Something went wrong with that request. Please try again.