]> granicus.if.org Git - python/commitdiff
Issue #22201: Command-line interface of the zipfile module now correctly
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 17 Aug 2014 12:14:48 +0000 (15:14 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 17 Aug 2014 12:14:48 +0000 (15:14 +0300)
extracts ZIP files with directory entries.  Patch by Ryan Wilson.

Lib/zipfile.py
Misc/NEWS

index ee228b14759ed13a2dd5946623917c000748f061..c57765753f1cc2d01148cb8e7314a9767c609c17 100644 (file)
@@ -1764,18 +1764,7 @@ def main(args = None):
             sys.exit(1)
 
         with ZipFile(args[1], 'r') as zf:
-            out = args[2]
-            for path in zf.namelist():
-                if path.startswith('./'):
-                    tgt = os.path.join(out, path[2:])
-                else:
-                    tgt = os.path.join(out, path)
-
-                tgtdir = os.path.dirname(tgt)
-                if not os.path.exists(tgtdir):
-                    os.makedirs(tgtdir)
-                with open(tgt, 'wb') as fp:
-                    fp.write(zf.read(path))
+            zf.extractall(args[2])
 
     elif args[0] == '-c':
         if len(args) < 3:
index 71304b3fcc9799440b846b95bfe09e8abeae66d6..15f2b8259710009702c4ca08071bdd12aa948868 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -329,6 +329,9 @@ Windows
 Tools/Demos
 -----------
 
+- Issue #22201: Command-line interface of the zipfile module now correctly
+  extracts ZIP files with directory entries.  Patch by Ryan Wilson.
+
 - Issue #21906: Make Tools/scripts/md5sum.py work in Python 3.
   Patch by Zachary Ware.