~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/dir_exporter.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Export a Tree to a non-versioned directory.
18
 
"""
 
17
"""Export a bzrlib.tree.Tree to a new or empty directory."""
19
18
 
20
19
import errno
21
20
import os
22
 
import StringIO
 
21
import time
23
22
 
24
23
from bzrlib import errors, osutils
25
24
from bzrlib.export import _export_iter_entries
30
29
from bzrlib.trace import mutter
31
30
 
32
31
 
33
 
def dir_exporter(tree, dest, root, subdir, filtered=False):
 
32
def dir_exporter(tree, dest, root, subdir, filtered=False,
 
33
                 per_file_timestamps=False):
34
34
    """Export this tree to a new directory.
35
35
 
36
 
    `dest` should not exist, and will be created holding the
37
 
    contents of this tree.
38
 
 
39
 
    TODO: To handle subdirectories we need to create the
40
 
           directories first.
 
36
    `dest` should either not exist or should be empty. If it does not exist it
 
37
    will be created holding the contents of this tree.
41
38
 
42
39
    :note: If the export fails, the destination directory will be
43
 
           left in a half-assed state.
 
40
           left in an incompletely exported state: export is not transactional.
44
41
    """
45
42
    mutter('export version %r', tree)
46
43
    try:
79
76
    # The data returned here can be in any order, but we've already created all
80
77
    # the directories
81
78
    flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | getattr(os, 'O_BINARY', 0)
 
79
    now = time.time()
82
80
    for (relpath, executable), chunks in tree.iter_files_bytes(to_fetch):
83
81
        if filtered:
84
82
            filters = tree._content_filter_stack(relpath)
94
92
            out.writelines(chunks)
95
93
        finally:
96
94
            out.close()
 
95
        if per_file_timestamps:
 
96
            mtime = tree.get_file_mtime(tree.path2id(relpath), relpath)
 
97
        else:
 
98
            mtime = now
 
99
        os.utime(fullpath, (mtime, mtime))