From 5c4c4619b0144684a1309de746809879b04848fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gust=C3=A4bel?= Date: Thu, 29 Apr 2010 15:23:38 +0000 Subject: Issue #8464: tarfile.open(name, mode="w|") no longer creates files with execute permissions set. --- Lib/tarfile.py | 2 +- Lib/test/test_tarfile.py | 18 ++++++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 45928fd..b0af5b1 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -380,7 +380,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) diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index eb368cf..52d6ab3 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -847,6 +847,24 @@ class StreamWriteTest(WriteTestBase): self.assertTrue(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 diff --git a/Misc/NEWS b/Misc/NEWS index 470c07c..73761ee 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -31,6 +31,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. -- cgit v0.12