diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2008-07-25 19:42:26 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2008-07-25 19:42:26 (GMT) |
commit | 5fdfa3e36d08e8627cd57d2f9653e1ec634f8355 (patch) | |
tree | ff25b4e170ef2805c97c129fed0aa681e6fcea23 | |
parent | 8c664e8628ace6a9f3b64980af262b67cd7f3e59 (diff) | |
download | cpython-5fdfa3e36d08e8627cd57d2f9653e1ec634f8355.zip cpython-5fdfa3e36d08e8627cd57d2f9653e1ec634f8355.tar.gz cpython-5fdfa3e36d08e8627cd57d2f9653e1ec634f8355.tar.bz2 |
#3394: zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix
-rw-r--r-- | Lib/test/test_zipfile.py | 13 | ||||
-rw-r--r-- | Lib/zipfile.py | 1 | ||||
-rw-r--r-- | Misc/NEWS | 4 |
3 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 90ac4f6..5e99382 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -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) diff --git a/Lib/zipfile.py b/Lib/zipfile.py index ddeaa18..609dea3 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -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 @@ -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? ================================ |