~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/tar_exporter.py

  • Committer: Jelmer Vernooij
  • Date: 2011-03-13 22:09:09 UTC
  • mto: This revision was merged to the branch mainline in revision 5724.
  • Revision ID: jelmer@samba.org-20110313220909-u654euthfvq912fe
Only write out basename of the tarfile to the gzip file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Export a Tree to a non-versioned directory.
18
18
"""
19
19
 
 
20
import os
20
21
import StringIO
21
22
import sys
22
23
import tarfile
92
93
    already exists, it will be clobbered, like with "tar -c".
93
94
    """
94
95
    import gzip
95
 
    if force_mtime is None and tree.root.id:
 
96
    if force_mtime is None and tree.get_root_id():
96
97
        # FIXME: Use tree.get_revision_id()'s timestamp ?
97
 
        root_mtime = tree.get_file_mtime(tree.root.id)
 
98
        root_mtime = tree.get_file_mtime(tree.get_root_id())
98
99
    else:
99
100
        root_mtime = force_mtime
100
101
    if dest == '-':
103
104
        stream = gzip.GzipFile(None, mode='w', mtime=root_mtime,
104
105
            fileobj=sys.stdout)
105
106
    else:
106
 
        stream = gzip.GzipFile(dest.encode(osutils._fs_enc), 'w',
107
 
            mtime=root_mtime)
108
 
    ball = tarfile.open(root, 'w|', fileobj=stream)
 
107
        stream = open(dest.encode(osutils._fs_enc), 'w')
 
108
        # gzip file is used with an explicit fileobj so that
 
109
        # the basename can be stored in the gzip file rather than
 
110
        # dest. (bug 102234)
 
111
        stream = gzip.GzipFile(os.path.basename(dest), 'w',
 
112
            mtime=root_mtime, fileobj=stream)
 
113
    ball = tarfile.open(None, 'w|', fileobj=stream)
109
114
    export_tarball(tree, ball, root, subdir, filtered=filtered,
110
115
                   force_mtime=force_mtime)
111
116
    ball.close()
118
123
    already exists, it will be clobbered, like with "tar -c".
119
124
    """
120
125
    if dest == '-':
121
 
        # XXX: If no root is given, the output tarball will contain files
122
 
        # named '-/foo'; perhaps this is the most reasonable thing.
123
126
        ball = tarfile.open(None, 'w|bz2', sys.stdout)
124
127
    else:
125
128
        # tarfile.open goes on to do 'os.getcwd() + dest' for opening
141
144
    already exists, it will be clobbered, like with "tar -c".
142
145
    """
143
146
    if dest == '-':
144
 
        # XXX: If no root is given, the output tarball will contain files
145
 
        # named '-/foo'; perhaps this is the most reasonable thing.
146
 
        ball = tarfile.open(None, 'w|', sys.stdout)
 
147
        stream = sys.stdout
147
148
    else:
148
 
        # tarfile.open goes on to do 'os.getcwd() + dest' for opening
149
 
        # the tar file. With dest being unicode, this throws UnicodeDecodeError
150
 
        # unless we encode dest before passing it on. This works around
151
 
        # upstream python bug http://bugs.python.org/issue8396
152
 
        # (fixed in Python 2.6.5 and 2.7b1)
153
 
        ball = tarfile.open(dest.encode(osutils._fs_enc), 'w:')
 
149
        stream = open(dest.encode(osutils._fs_enc), 'w')
 
150
    ball = tarfile.open(None, 'w|', stream)
154
151
    export_tarball(tree, ball, root, subdir, filtered=filtered,
155
152
                   force_mtime=force_mtime)
156
153
    ball.close()
171
168
        raise errors.DependencyNotPresent('lzma', e)
172
169
 
173
170
    stream = lzma.LZMAFile(dest.encode(osutils._fs_enc), 'w')
174
 
    ball = tarfile.open(root, 'w:', fileobj=stream)
 
171
    ball = tarfile.open(None, 'w:', fileobj=stream)
175
172
    export_tarball(tree, ball, root, subdir, filtered=filtered,
176
173
                   force_mtime=force_mtime)
177
174
    ball.close()