]> granicus.if.org Git - python/commitdiff
Issue #22219: The zipfile module CLI now adds entries for directories
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 4 Oct 2014 10:39:34 +0000 (13:39 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 4 Oct 2014 10:39:34 +0000 (13:39 +0300)
(including empty directories) in ZIP file.

Lib/zipfile.py
Misc/NEWS

index 7e07f11d79accf4ce6703a7be6759cdef59b3f1a..bda61343571601a4f13a409d5e5020ed677b150b 100644 (file)
@@ -1790,14 +1790,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') 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()
index 5934d5bc32478e6c6adbbe5cccdc987463c8c817..671cc502701afa4de7fbe89926a16b09e357e81a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,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.