~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/dir_exporter.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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
 
22
24
from bzrlib import errors, osutils
23
25
from bzrlib.export import _export_iter_entries
24
 
from bzrlib.filters import (
25
 
    ContentFilterContext,
26
 
    filtered_output_bytes,
27
 
    )
28
 
 
29
 
 
30
 
def dir_exporter_generator(tree, dest, root, subdir=None, filtered=False,
 
26
 
 
27
 
 
28
def dir_exporter_generator(tree, dest, root, subdir=None,
31
29
                           force_mtime=None, fileobj=None):
32
30
    """Return a generator that exports this tree to a new directory.
33
31
 
56
54
    # Note in the case of revision trees, this does trigger a double inventory
57
55
    # lookup, hopefully it isn't too expensive.
58
56
    to_fetch = []
59
 
    for dp, ie in _export_iter_entries(tree, subdir):
 
57
    for dp, tp, ie in _export_iter_entries(tree, subdir):
60
58
        fullpath = osutils.pathjoin(dest, dp)
61
59
        if ie.kind == "file":
62
 
            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)))
63
61
        elif ie.kind == "directory":
64
62
            os.mkdir(fullpath)
65
63
        elif ie.kind == "symlink":
66
64
            try:
67
 
                symlink_target = tree.get_symlink_target(ie.file_id)
 
65
                symlink_target = tree.get_symlink_target(ie.file_id, tp)
68
66
                os.symlink(symlink_target, fullpath)
69
67
            except OSError, e:
70
68
                raise errors.BzrError(
78
76
    # The data returned here can be in any order, but we've already created all
79
77
    # the directories
80
78
    flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | getattr(os, 'O_BINARY', 0)
81
 
    for (relpath, executable), chunks in tree.iter_files_bytes(to_fetch):
82
 
        if filtered:
83
 
            filters = tree._content_filter_stack(relpath)
84
 
            context = ContentFilterContext(relpath, tree, ie)
85
 
            chunks = filtered_output_bytes(chunks, filters, context)
 
79
    for (relpath, treepath, file_id), chunks in tree.iter_files_bytes(to_fetch):
86
80
        fullpath = osutils.pathjoin(dest, relpath)
87
81
        # We set the mode and let the umask sort out the file info
88
82
        mode = 0666
89
 
        if executable:
 
83
        if tree.is_executable(file_id, treepath):
90
84
            mode = 0777
91
85
        out = os.fdopen(os.open(fullpath, flags, mode), 'wb')
92
86
        try:
96
90
        if force_mtime is not None:
97
91
            mtime = force_mtime
98
92
        else:
99
 
            if subdir is None:
100
 
                file_id = tree.path2id(relpath)
101
 
            else:
102
 
                file_id = tree.path2id(osutils.pathjoin(subdir, relpath))
103
 
            mtime = tree.get_file_mtime(file_id, relpath)
 
93
            mtime = tree.get_file_mtime(file_id, treepath)
104
94
        os.utime(fullpath, (mtime, mtime))
105
95
 
106
96
        yield