~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/tar_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 tree to a tarball."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import os
20
22
import StringIO
21
23
import sys
28
30
from bzrlib.export import _export_iter_entries
29
31
 
30
32
 
31
 
def prepare_tarball_item(tree, root, final_path, entry, force_mtime=None):
 
33
def prepare_tarball_item(tree, root, final_path, tree_path, entry, force_mtime=None):
32
34
    """Prepare a tarball item for exporting
33
35
 
34
36
    :param tree: Tree to export
35
 
 
36
37
    :param final_path: Final path to place item
37
 
 
 
38
    :param tree_path: Path for the entry in the tree
38
39
    :param entry: Entry to export
39
 
 
40
40
    :param force_mtime: Option mtime to force, instead of using tree
41
41
        timestamps.
42
42
 
47
47
    if force_mtime is not None:
48
48
        item.mtime = force_mtime
49
49
    else:
50
 
        item.mtime = tree.get_file_mtime(entry.file_id, final_path)
 
50
        item.mtime = tree.get_file_mtime(entry.file_id, tree_path)
51
51
    if entry.kind == "file":
52
52
        item.type = tarfile.REGTYPE
53
 
        if tree.is_executable(entry.file_id):
 
53
        if tree.is_executable(entry.file_id, tree_path):
54
54
            item.mode = 0755
55
55
        else:
56
56
            item.mode = 0644
58
58
        # the tarfile contract, which wants the size of the file up front.  We
59
59
        # want to make sure it doesn't change, and we need to read it in one
60
60
        # go for content filtering.
61
 
        content = tree.get_file_text(entry.file_id)
 
61
        content = tree.get_file_text(entry.file_id, tree_path)
62
62
        item.size = len(content)
63
63
        fileobj = StringIO.StringIO(content)
64
64
    elif entry.kind == "directory":
71
71
        item.type = tarfile.SYMTYPE
72
72
        item.size = 0
73
73
        item.mode = 0755
74
 
        item.linkname = tree.get_symlink_target(entry.file_id)
 
74
        item.linkname = tree.get_symlink_target(entry.file_id, tree_path)
75
75
        fileobj = None
76
76
    else:
77
77
        raise errors.BzrError("don't know how to export {%s} of kind %r"
97
97
        timestamps.
98
98
    """
99
99
    try:
100
 
        for final_path, entry in _export_iter_entries(tree, subdir):
 
100
        for final_path, tree_path, entry in _export_iter_entries(tree, subdir):
101
101
            (item, fileobj) = prepare_tarball_item(
102
 
                tree, root, final_path, entry, force_mtime)
 
102
                tree, root, final_path, tree_path, entry, force_mtime)
103
103
            ball.addfile(item, fileobj)
104
104
            yield
105
105
    finally: