/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

Merge test-run support.

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
 
                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)
60
61
 
61
62
                # zipfile.ZipFile switches all paths to forward
62
63
                # slashes anyway, so just stick with that.
63
64
                if force_mtime is not None:
64
65
                    mtime = force_mtime
65
66
                else:
66
 
                    mtime = tree.get_file_mtime(tp)
 
67
                    mtime = tree.get_file_mtime(tp, file_id)
67
68
                date_time = time.localtime(mtime)[:6]
68
 
                filename = osutils.pathjoin(root, dp)
 
69
                filename = osutils.pathjoin(root, dp).encode('utf8')
69
70
                if ie.kind == "file":
70
71
                    zinfo = zipfile.ZipInfo(
71
 
                        filename=filename,
72
 
                        date_time=date_time)
 
72
                                filename=filename,
 
73
                                date_time=date_time)
73
74
                    zinfo.compress_type = compression
74
75
                    zinfo.external_attr = _FILE_ATTR
75
 
                    content = tree.get_file_text(tp)
 
76
                    content = tree.get_file_text(tp, file_id)
76
77
                    zipf.writestr(zinfo, content)
77
78
                elif ie.kind in ("directory", "tree-reference"):
78
79
                    # Directories must contain a trailing slash, to indicate
79
80
                    # to the zip routine that they are really directories and
80
81
                    # not just empty files.
81
82
                    zinfo = zipfile.ZipInfo(
82
 
                        filename=filename + '/',
83
 
                        date_time=date_time)
 
83
                                filename=filename + '/',
 
84
                                date_time=date_time)
84
85
                    zinfo.compress_type = compression
85
86
                    zinfo.external_attr = _DIR_ATTR
86
87
                    zipf.writestr(zinfo, '')
87
88
                elif ie.kind == "symlink":
88
89
                    zinfo = zipfile.ZipInfo(
89
 
                        filename=(filename + '.lnk'),
90
 
                        date_time=date_time)
 
90
                                filename=(filename + '.lnk'),
 
91
                                date_time=date_time)
91
92
                    zinfo.compress_type = compression
92
93
                    zinfo.external_attr = _FILE_ATTR
93
 
                    zipf.writestr(zinfo, tree.get_symlink_target(tp))
 
94
                    zipf.writestr(zinfo, tree.get_symlink_target(tp, file_id))
94
95
        # Urgh, headers are written last since they include e.g. file size.
95
96
        # So we have to buffer it all :(
96
97
        buf.seek(0)