/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/archive/zip.py

  • Committer: Jelmer Vernooij
  • Date: 2018-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Export a Tree to a zip file.
18
18
"""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
from contextlib import closing
21
23
import os
22
24
import stat
43
45
 
44
46
 
45
47
def zip_archive_generator(tree, dest, root, subdir=None,
46
 
                          force_mtime=None):
 
48
    force_mtime=None):
47
49
    """ Export this tree to a new zip file.
48
50
 
49
51
    `dest` will be created holding the contents of this tree; if it
52
54
    compression = zipfile.ZIP_DEFLATED
53
55
    with tempfile.SpooledTemporaryFile() as buf:
54
56
        with closing(zipfile.ZipFile(buf, "w", compression)) as zipf, \
55
 
                tree.lock_read():
 
57
             tree.lock_read():
56
58
            for dp, tp, ie in _export_iter_entries(tree, subdir):
57
 
                mutter("  export {%s} kind %s to %s", tp, ie.kind, dest)
 
59
                file_id = getattr(ie, 'file_id', None)
 
60
                mutter("  export {%s} kind %s to %s", file_id, ie.kind, dest)
58
61
 
59
62
                # zipfile.ZipFile switches all paths to forward
60
63
                # slashes anyway, so just stick with that.
61
64
                if force_mtime is not None:
62
65
                    mtime = force_mtime
63
66
                else:
64
 
                    mtime = tree.get_file_mtime(tp)
 
67
                    mtime = tree.get_file_mtime(tp, file_id)
65
68
                date_time = time.localtime(mtime)[:6]
66
 
                filename = osutils.pathjoin(root, dp)
 
69
                filename = osutils.pathjoin(root, dp).encode('utf8')
67
70
                if ie.kind == "file":
68
71
                    zinfo = zipfile.ZipInfo(
69
 
                        filename=filename,
70
 
                        date_time=date_time)
 
72
                                filename=filename,
 
73
                                date_time=date_time)
71
74
                    zinfo.compress_type = compression
72
75
                    zinfo.external_attr = _FILE_ATTR
73
 
                    content = tree.get_file_text(tp)
 
76
                    content = tree.get_file_text(tp, file_id)
74
77
                    zipf.writestr(zinfo, content)
75
78
                elif ie.kind in ("directory", "tree-reference"):
76
79
                    # Directories must contain a trailing slash, to indicate
77
80
                    # to the zip routine that they are really directories and
78
81
                    # not just empty files.
79
82
                    zinfo = zipfile.ZipInfo(
80
 
                        filename=filename + '/',
81
 
                        date_time=date_time)
 
83
                                filename=filename + '/',
 
84
                                date_time=date_time)
82
85
                    zinfo.compress_type = compression
83
86
                    zinfo.external_attr = _DIR_ATTR
84
87
                    zipf.writestr(zinfo, '')
85
88
                elif ie.kind == "symlink":
86
89
                    zinfo = zipfile.ZipInfo(
87
 
                        filename=(filename + '.lnk'),
88
 
                        date_time=date_time)
 
90
                                filename=(filename + '.lnk'),
 
91
                                date_time=date_time)
89
92
                    zinfo.compress_type = compression
90
93
                    zinfo.external_attr = _FILE_ATTR
91
 
                    zipf.writestr(zinfo, tree.get_symlink_target(tp))
 
94
                    zipf.writestr(zinfo, tree.get_symlink_target(tp, file_id))
92
95
        # Urgh, headers are written last since they include e.g. file size.
93
96
        # So we have to buffer it all :(
94
97
        buf.seek(0)