~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/dir_exporter.py

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Export a bzrlib.tree.Tree to a new or empty directory."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import errno
20
22
import os
21
23
 
52
54
    # Note in the case of revision trees, this does trigger a double inventory
53
55
    # lookup, hopefully it isn't too expensive.
54
56
    to_fetch = []
55
 
    for dp, ie in _export_iter_entries(tree, subdir):
 
57
    for dp, tp, ie in _export_iter_entries(tree, subdir):
56
58
        fullpath = osutils.pathjoin(dest, dp)
57
59
        if ie.kind == "file":
58
 
            to_fetch.append((ie.file_id, (dp, tree.is_executable(ie.file_id))))
 
60
            to_fetch.append((ie.file_id, (dp, tp, ie.file_id)))
59
61
        elif ie.kind == "directory":
60
62
            os.mkdir(fullpath)
61
63
        elif ie.kind == "symlink":
62
64
            try:
63
 
                symlink_target = tree.get_symlink_target(ie.file_id)
 
65
                symlink_target = tree.get_symlink_target(ie.file_id, tp)
64
66
                os.symlink(symlink_target, fullpath)
65
67
            except OSError, e:
66
68
                raise errors.BzrError(
74
76
    # The data returned here can be in any order, but we've already created all
75
77
    # the directories
76
78
    flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | getattr(os, 'O_BINARY', 0)
77
 
    for (relpath, executable), chunks in tree.iter_files_bytes(to_fetch):
 
79
    for (relpath, treepath, file_id), chunks in tree.iter_files_bytes(to_fetch):
78
80
        fullpath = osutils.pathjoin(dest, relpath)
79
81
        # We set the mode and let the umask sort out the file info
80
82
        mode = 0666
81
 
        if executable:
 
83
        if tree.is_executable(file_id, treepath):
82
84
            mode = 0777
83
85
        out = os.fdopen(os.open(fullpath, flags, mode), 'wb')
84
86
        try:
88
90
        if force_mtime is not None:
89
91
            mtime = force_mtime
90
92
        else:
91
 
            if subdir is None:
92
 
                file_id = tree.path2id(relpath)
93
 
            else:
94
 
                file_id = tree.path2id(osutils.pathjoin(subdir, relpath))
95
 
            mtime = tree.get_file_mtime(file_id, relpath)
 
93
            mtime = tree.get_file_mtime(file_id, treepath)
96
94
        os.utime(fullpath, (mtime, mtime))
97
95
 
98
96
        yield