21
27
from bzrlib.trace import mutter
30
# Windows expects this bit to be set in the 'external_attr' section
31
# Or it won't consider the entry a directory
32
ZIP_DIRECTORY_BIT = (1 << 4)
34
_FILE_ATTR = stat.S_IFREG
35
_DIR_ATTR = stat.S_IFDIR | ZIP_DIRECTORY_BIT
24
38
def zip_exporter(tree, dest, root):
25
39
""" Export this tree to a new zip file.
49
63
file_id = ie.file_id
50
64
mutter(" export {%s} kind %s to %s", file_id, ie.kind, dest)
66
# zipfile.ZipFile switches all paths to forward
67
# slashes anyway, so just stick with that.
68
filename = osutils.pathjoin(root, dp).encode('utf8')
53
70
zinfo = zipfile.ZipInfo(
54
filename=str(os.path.join(root, dp)),
56
73
zinfo.compress_type = compression
74
zinfo.external_attr = _FILE_ATTR
57
75
zipf.writestr(zinfo, tree.get_file_text(file_id))
58
76
elif ie.kind == "directory":
77
# Directories must contain a trailing slash, to indicate
78
# to the zip routine that they are really directories and
79
# not just empty files.
59
80
zinfo = zipfile.ZipInfo(
60
filename=str(os.path.join(root, dp)+os.sep),
81
filename=filename + '/',
62
83
zinfo.compress_type = compression
84
zinfo.external_attr = _DIR_ATTR
63
85
zipf.writestr(zinfo,'')
64
86
elif ie.kind == "symlink":
65
87
zinfo = zipfile.ZipInfo(
66
filename=str(os.path.join(root, dp+".lnk")),
88
filename=(filename + '.lnk'),
68
90
zinfo.compress_type = compression
91
zinfo.external_attr = _FILE_ATTR
69
92
zipf.writestr(zinfo, ie.symlink_target)