~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/dir_exporter.py

Merge cleanup into description

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2009 Canonical Ltd
 
1
# Copyright (C) 2005, 2009-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
21
import StringIO
 
22
import time
23
23
 
24
24
from bzrlib import errors, osutils
25
25
from bzrlib.export import _export_iter_entries
33
33
def dir_exporter(tree, dest, root, subdir, filtered=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
        os.utime(fullpath, (now, now))