/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-11-16 23:15:15 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7183.
  • Revision ID: jelmer@jelmer.uk-20181116231515-zqd2yn6kj8lfydyp
Merge trunk.

Show diffs side-by-side

added added

removed removed

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