[Python-checkins] r65235 - in python/trunk: Lib/test/test_zipfile.py Lib/zipfile.py Misc/NEWS

antoine.pitrou python-checkins at python.org
Fri Jul 25 21:42:26 CEST 2008


Author: antoine.pitrou
Date: Fri Jul 25 21:42:26 2008
New Revision: 65235

Log:
#3394: zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix



Modified:
   python/trunk/Lib/test/test_zipfile.py
   python/trunk/Lib/zipfile.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Lib/test/test_zipfile.py
==============================================================================
--- python/trunk/Lib/test/test_zipfile.py	(original)
+++ python/trunk/Lib/test/test_zipfile.py	Fri Jul 25 21:42:26 2008
@@ -372,6 +372,19 @@
         # 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)

Modified: python/trunk/Lib/zipfile.py
==============================================================================
--- python/trunk/Lib/zipfile.py	(original)
+++ python/trunk/Lib/zipfile.py	Fri Jul 25 21:42:26 2008
@@ -1064,6 +1064,7 @@
             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
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri Jul 25 21:42:26 2008
@@ -44,6 +44,10 @@
 
 - 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?
 ================================


More information about the Python-checkins mailing list