summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-10-04 10:39:18 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-10-04 10:39:18 (GMT)
commit52313d72faa199e2e40a3bd5e88fa0b5f5a0bc61 (patch)
tree7d41fe16209efb4e1ce6eb7c4e98ffb85a554384
parentc6cf35d36d8b1a9d741f86ce8d80a005ff23ba8e (diff)
downloadcpython-52313d72faa199e2e40a3bd5e88fa0b5f5a0bc61.zip
cpython-52313d72faa199e2e40a3bd5e88fa0b5f5a0bc61.tar.gz
cpython-52313d72faa199e2e40a3bd5e88fa0b5f5a0bc61.tar.bz2
Issue #22219: The zipfile module CLI now adds entries for directories
(including empty directories) in ZIP file.
-rw-r--r--Lib/zipfile.py11
-rw-r--r--Misc/NEWS3
2 files changed, 12 insertions, 2 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index ecdd8a5..b77e6c8 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -1519,14 +1519,21 @@ def main(args = None):
if os.path.isfile(path):
zf.write(path, zippath, ZIP_DEFLATED)
elif os.path.isdir(path):
+ if zippath:
+ zf.write(path, zippath)
for nm in os.listdir(path):
addToZip(zf,
os.path.join(path, nm), os.path.join(zippath, nm))
# else: ignore
with ZipFile(args[1], 'w', allowZip64=True) as zf:
- for src in args[2:]:
- addToZip(zf, src, os.path.basename(src))
+ for path in args[2:]:
+ zippath = os.path.basename(path)
+ if not zippath:
+ zippath = os.path.basename(os.path.dirname(path))
+ if zippath in ('', os.curdir, os.pardir):
+ zippath = ''
+ addToZip(zf, path, zippath)
if __name__ == "__main__":
main()
diff --git a/Misc/NEWS b/Misc/NEWS
index 17e3f8a..0a97051 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,9 @@ Core and Builtins
Library
-------
+- Issue #22219: The zipfile module CLI now adds entries for directories
+ (including empty directories) in ZIP file.
+
- Issue #22449: In the ssl.SSLContext.load_default_certs, consult the
enviromental variables SSL_CERT_DIR and SSL_CERT_FILE on Windows.