~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/core/files/move.py

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2014-09-17 14:15:11 UTC
  • mfrom: (1.3.17) (6.2.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140917141511-icneokthe9ww5sk4
Tags: 1.7-2
* Release to unstable.
* Add a migrate-south sample script to help users apply their South
  migrations. Thanks to Brian May.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
    from shutil import copystat
13
13
except ImportError:
14
14
    import stat
 
15
 
15
16
    def copystat(src, dst):
16
17
        """Copy all stat info (mode bits, atime and mtime) from src to dst"""
17
18
        st = os.stat(src)
23
24
 
24
25
__all__ = ['file_move_safe']
25
26
 
 
27
 
26
28
def _samefile(src, dst):
27
29
    # Macintosh, Unix.
28
 
    if hasattr(os.path,'samefile'):
 
30
    if hasattr(os.path, 'samefile'):
29
31
        try:
30
32
            return os.path.samefile(src, dst)
31
33
        except OSError:
35
37
    return (os.path.normcase(os.path.abspath(src)) ==
36
38
            os.path.normcase(os.path.abspath(dst)))
37
39
 
38
 
def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_overwrite=False):
 
40
 
 
41
def file_move_safe(old_file_name, new_file_name, chunk_size=1024 * 64, allow_overwrite=False):
39
42
    """
40
43
    Moves a file from one location to another in the safest way possible.
41
44
 
65
68
    # first open the old file, so that it won't go away
66
69
    with open(old_file_name, 'rb') as old_file:
67
70
        # now open the new file, not forgetting allow_overwrite
68
 
        fd = os.open(new_file_name, os.O_WRONLY | os.O_CREAT | getattr(os, 'O_BINARY', 0) |
69
 
                                    (os.O_EXCL if not allow_overwrite else 0))
 
71
        fd = os.open(new_file_name, (os.O_WRONLY | os.O_CREAT | getattr(os, 'O_BINARY', 0) |
 
72
                                     (os.O_EXCL if not allow_overwrite else 0)))
70
73
        try:
71
74
            locks.lock(fd, locks.LOCK_EX)
72
75
            current_chunk = None