~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/dir_exporter.py

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import errno
20
20
import os
21
 
import time
22
21
 
23
22
from bzrlib import errors, osutils
24
23
from bzrlib.export import _export_iter_entries
26
25
    ContentFilterContext,
27
26
    filtered_output_bytes,
28
27
    )
29
 
from bzrlib.trace import mutter
30
 
 
31
 
 
32
 
def dir_exporter(tree, dest, root, subdir, filtered=False,
33
 
                 per_file_timestamps=False):
 
28
 
 
29
 
 
30
def dir_exporter(tree, dest, root, subdir=None, filtered=False, force_mtime=None):
34
31
    """Export this tree to a new directory.
35
32
 
36
33
    `dest` should either not exist or should be empty. If it does not exist it
39
36
    :note: If the export fails, the destination directory will be
40
37
           left in an incompletely exported state: export is not transactional.
41
38
    """
42
 
    mutter('export version %r', tree)
43
39
    try:
44
40
        os.mkdir(dest)
45
41
    except OSError, e:
76
72
    # The data returned here can be in any order, but we've already created all
77
73
    # the directories
78
74
    flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | getattr(os, 'O_BINARY', 0)
79
 
    now = time.time()
80
75
    for (relpath, executable), chunks in tree.iter_files_bytes(to_fetch):
81
76
        if filtered:
82
77
            filters = tree._content_filter_stack(relpath)
92
87
            out.writelines(chunks)
93
88
        finally:
94
89
            out.close()
95
 
        if per_file_timestamps:
 
90
        if force_mtime is not None:
 
91
            mtime = force_mtime
 
92
        else:
96
93
            mtime = tree.get_file_mtime(tree.path2id(relpath), relpath)
97
 
        else:
98
 
            mtime = now
99
94
        os.utime(fullpath, (mtime, mtime))