]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#3394: zipfile.writestr doesn't set external attributes, so files are extracted mode...
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 25 Jul 2008 19:42:26 +0000 (19:42 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 25 Jul 2008 19:42:26 +0000 (19:42 +0000)
Lib/test/test_zipfile.py
Lib/zipfile.py
Misc/NEWS

index 90ac4f6f6ee57ff2c43f42dc118b6714a6fc436b..5e993821ab237f4a9d09a6648bee3e0c7b1dc040 100644 (file)
@@ -372,6 +372,19 @@ class TestsWithSourceFile(unittest.TestCase):
         # remove the test file subdirectories
         shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
 
+    def zip_test_writestr_permissions(self, f, compression):
+        # Make sure that writestr creates files with mode 0600,
+        # when it is passed a name rather than a ZipInfo instance.
+
+        self.makeTestArchive(f, compression)
+        zipfp = zipfile.ZipFile(f, "r")
+        zinfo = zipfp.getinfo('strfile')
+        self.assertEqual(zinfo.external_attr, 0600 << 16)
+
+    def test_writestr_permissions(self):
+        for f in (TESTFN2, TemporaryFile(), StringIO()):
+            self.zip_test_writestr_permissions(f, zipfile.ZIP_STORED)
+
     def tearDown(self):
         os.remove(TESTFN)
         os.remove(TESTFN2)
index ddeaa18c142543fd1937e40f600d61e30a93889f..609dea3f273d7db5866c705e38f1511a6cbb694b 100644 (file)
@@ -1064,6 +1064,7 @@ class ZipFile:
             zinfo = ZipInfo(filename=zinfo_or_arcname,
                             date_time=time.localtime(time.time())[:6])
             zinfo.compress_type = self.compression
+            zinfo.external_attr = 0600 << 16
         else:
             zinfo = zinfo_or_arcname
 
index 87ef02d3256b40e55ae7be229078aec60ba71200..995c7c3b42478e0415771c49517acc401f2e7f3d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,6 +44,10 @@ Library
 
 - Deprecate the sunaudio module for removal in Python 3.0.
 
+- Issue #3394: zipfile.writestr sets external attributes when passed a
+  file name rather than a ZipInfo instance, so files are extracted with
+  mode 0600 rather than 000 under Unix.
+
 
 What's New in Python 2.6 beta 2?
 ================================