[Python-checkins] cpython (2.7): Issue #22219: The zipfile module CLI now adds entries for directories
serhiy.storchaka
python-checkins at python.org
Sat Oct 4 12:56:20 CEST 2014
https://hg.python.org/cpython/rev/911da1072099
changeset: 92785:911da1072099
branch: 2.7
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sat Oct 04 13:39:18 2014 +0300
summary:
Issue #22219: The zipfile module CLI now adds entries for directories
(including empty directories) in ZIP file.
files:
Lib/zipfile.py | 11 +++++++++--
Misc/NEWS | 3 +++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -1519,14 +1519,21 @@
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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,9 @@
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.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list