mirror of https://github.com/python/cpython
Issue 6070: when creating a compiled file, after copying the mode bits, on
posix zap the execute bit in case it was set on the .py file, since the compiled files are not directly executable on posix. Patch by Marco N.
This commit is contained in:
parent
e670e5ad5b
commit
23a736a4f0
|
@ -1,5 +1,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
|
import stat
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
@ -91,6 +92,23 @@ class ImportTest(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
del sys.path[0]
|
del sys.path[0]
|
||||||
|
|
||||||
|
@unittest.skipUnless(os.name == 'posix', "test meaningful only on posix systems")
|
||||||
|
def test_execute_bit_not_copied(self):
|
||||||
|
# Issue 6070: under posix .pyc files got their execute bit set if
|
||||||
|
# the .py file had the execute bit set, but they aren't executable.
|
||||||
|
try:
|
||||||
|
fname = TESTFN + os.extsep + "py"
|
||||||
|
f = open(fname, 'w').close()
|
||||||
|
os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
|
||||||
|
stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
|
||||||
|
__import__(TESTFN)
|
||||||
|
s = os.stat(fname + 'c')
|
||||||
|
self.assertEquals(stat.S_IMODE(s.st_mode),
|
||||||
|
stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
|
||||||
|
finally:
|
||||||
|
remove_files(TESTFN)
|
||||||
|
del sys.modules[TESTFN]
|
||||||
|
|
||||||
def testImpModule(self):
|
def testImpModule(self):
|
||||||
# Verify that the imp module can correctly load and find .py files
|
# Verify that the imp module can correctly load and find .py files
|
||||||
import imp
|
import imp
|
||||||
|
@ -232,6 +250,7 @@ class ImportTest(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
self.fail("import by path didn't raise an exception")
|
self.fail("import by path didn't raise an exception")
|
||||||
|
|
||||||
|
|
||||||
class TestPycRewriting(unittest.TestCase):
|
class TestPycRewriting(unittest.TestCase):
|
||||||
# Test that the `co_filename` attribute on code objects always points
|
# Test that the `co_filename` attribute on code objects always points
|
||||||
# to the right file, even when various things happen (e.g. both the .py
|
# to the right file, even when various things happen (e.g. both the .py
|
||||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue 6070: On posix platforms import no longer copies the execute bit
|
||||||
|
from the .py file to the .pyc file if it is set. Patch by Marco N.
|
||||||
|
|
||||||
- Issue #4618: When unicode arguments are passed to print(), the default
|
- Issue #4618: When unicode arguments are passed to print(), the default
|
||||||
separator and end should be unicode also.
|
separator and end should be unicode also.
|
||||||
|
|
||||||
|
|
|
@ -881,7 +881,9 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
time_t mtime = srcstat->st_mtime;
|
time_t mtime = srcstat->st_mtime;
|
||||||
mode_t mode = srcstat->st_mode;
|
#ifndef MS_WINDOWS
|
||||||
|
mode_t mode = srcstat->st_mode & ~S_IXUSR & ~S_IXGRP & ~S_IXOTH;
|
||||||
|
#endif
|
||||||
|
|
||||||
fp = open_exclusive(cpathname, mode);
|
fp = open_exclusive(cpathname, mode);
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
|
|
Loading…
Reference in New Issue