]> granicus.if.org Git - python/commitdiff
Merged revisions 80616 via svnmerge from
authorLars Gustäbel <lars@gustaebel.de>
Thu, 29 Apr 2010 15:37:02 +0000 (15:37 +0000)
committerLars Gustäbel <lars@gustaebel.de>
Thu, 29 Apr 2010 15:37:02 +0000 (15:37 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r80616 | lars.gustaebel | 2010-04-29 17:23:38 +0200 (Thu, 29 Apr 2010) | 4 lines

  Issue #8464: tarfile.open(name, mode="w|") no longer creates
  files with execute permissions set.
........

Lib/tarfile.py
Lib/test/test_tarfile.py
Misc/NEWS

index 86844932a501185627fe3245358e835a07f1966e..9ca8494fdc4bfc5e061288f13a10e0a46b665a9d 100644 (file)
@@ -359,7 +359,7 @@ class _LowLevelFile:
         }[mode]
         if hasattr(os, "O_BINARY"):
             mode |= os.O_BINARY
-        self.fd = os.open(name, mode)
+        self.fd = os.open(name, mode, 0o666)
 
     def close(self):
         os.close(self.fd)
index ff04ef835197e2017d40c400a53b4a6e06fc277e..43527ef32bfa50147b40e5c0f96f3022d7548d79 100644 (file)
@@ -846,6 +846,24 @@ class StreamWriteTest(WriteTestBase):
         self.assertTrue(data.count(b"\0") == tarfile.RECORDSIZE,
                          "incorrect zero padding")
 
+    def test_file_mode(self):
+        # Test for issue #8464: Create files with correct
+        # permissions.
+        if sys.platform == "win32" or not hasattr(os, "umask"):
+            return
+
+        if os.path.exists(tmpname):
+            os.remove(tmpname)
+
+        original_umask = os.umask(0o022)
+        try:
+            tar = tarfile.open(tmpname, self.mode)
+            tar.close()
+            mode = os.stat(tmpname).st_mode & 0o777
+            self.assertEqual(mode, 0o644, "wrong file permissions")
+        finally:
+            os.umask(original_umask)
+
 
 class GNUWriteTest(unittest.TestCase):
     # This testcase checks for correct creation of GNU Longname
index b3be6e9c8c7985b1f63831cf226fd63a55f446ad..8c507234687ca0603940c2974e66ae922f073676 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -339,6 +339,9 @@ C-API
 Library
 -------
 
+- Issue #8464: tarfile no longer creates files with execute permissions set
+  when mode="w|" is used.
+
 - Issue #7834: Fix connect() of Bluetooth L2CAP sockets with recent versions
   of the Linux kernel.  Patch by Yaniv Aknin.