]> granicus.if.org Git - python/commitdiff
Merged revisions 80616 via svnmerge from
authorLars Gustäbel <lars@gustaebel.de>
Thu, 29 Apr 2010 15:35:30 +0000 (15:35 +0000)
committerLars Gustäbel <lars@gustaebel.de>
Thu, 29 Apr 2010 15:35:30 +0000 (15:35 +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 7643a0bc647367f398c2a1b1a4f1eb243564c915..8c2d26b2e46eddd0513987fab1ab2fdc63b46d40 100644 (file)
@@ -370,7 +370,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, 0666)
 
     def close(self):
         os.close(self.fd)
index e2682c44cc80dcb9080d476fde00eda6133f4f53..786f57a9149e2dfb27576960c353689f6df8557f 100644 (file)
@@ -703,6 +703,24 @@ class StreamWriteTest(WriteTestBase):
         self.assert_(data.count("\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(0022)
+        try:
+            tar = tarfile.open(tmpname, self.mode)
+            tar.close()
+            mode = os.stat(tmpname).st_mode & 0777
+            self.assertEqual(mode, 0644, "wrong file permissions")
+        finally:
+            os.umask(original_umask)
+
 
 class GNUWriteTest(unittest.TestCase):
     # This testcase checks for correct creation of GNU Longname
index af424706ca00e002b9fc4d4b322987f0d81bb9b9..16a419040dc6d381c48f949e1866b51afa6124e6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,9 @@ Core and Builtins
 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.