Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b48c028c
Commit
b48c028c
authored
Oct 19, 2012
by
Nick Coghlan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #6074: Restore the long-broken support for running with read-only source files on Windows
parent
02f69f69
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
1 deletion
+56
-1
Lib/test/test_import.py
Lib/test/test_import.py
+47
-1
Misc/NEWS
Misc/NEWS
+3
-0
Python/import.c
Python/import.c
+6
-0
No files found.
Lib/test/test_import.py
View file @
b48c028c
...
@@ -15,12 +15,24 @@ from test.test_support import (unlink, TESTFN, unload, run_unittest, rmtree,
...
@@ -15,12 +15,24 @@ from test.test_support import (unlink, TESTFN, unload, run_unittest, rmtree,
from
test
import
symlink_support
from
test
import
symlink_support
from
test
import
script_helper
from
test
import
script_helper
def
remove
_files
(
name
):
def
_iter
_files
(
name
):
for
f
in
(
name
+
os
.
extsep
+
"py"
,
for
f
in
(
name
+
os
.
extsep
+
"py"
,
name
+
os
.
extsep
+
"pyc"
,
name
+
os
.
extsep
+
"pyc"
,
name
+
os
.
extsep
+
"pyo"
,
name
+
os
.
extsep
+
"pyo"
,
name
+
os
.
extsep
+
"pyw"
,
name
+
os
.
extsep
+
"pyw"
,
name
+
"$py.class"
):
name
+
"$py.class"
):
yield
f
def
chmod_files
(
name
):
for
f
in
_iter_files
(
name
):
try
:
os
.
chmod
(
f
,
0600
)
except
OSError
as
exc
:
if
exc
.
errno
!=
errno
.
ENOENT
:
raise
def
remove_files
(
name
):
for
f
in
_iter_files
(
name
):
unlink
(
f
)
unlink
(
f
)
...
@@ -120,6 +132,40 @@ class ImportTests(unittest.TestCase):
...
@@ -120,6 +132,40 @@ class ImportTests(unittest.TestCase):
unload
(
TESTFN
)
unload
(
TESTFN
)
del
sys
.
path
[
0
]
del
sys
.
path
[
0
]
def
test_rewrite_pyc_with_read_only_source
(
self
):
# Issue 6074: a long time ago on posix, and more recently on Windows,
# a read only source file resulted in a read only pyc file, which
# led to problems with updating it later
sys
.
path
.
insert
(
0
,
os
.
curdir
)
fname
=
TESTFN
+
os
.
extsep
+
"py"
try
:
# Write a Python file, make it read-only and import it
with
open
(
fname
,
'w'
)
as
f
:
f
.
write
(
"x = 'original'
\
n
"
)
# Tweak the mtime of the source to ensure pyc gets updated later
s
=
os
.
stat
(
fname
)
os
.
utime
(
fname
,
(
s
.
st_atime
,
s
.
st_mtime
-
100000000
))
os
.
chmod
(
fname
,
0400
)
m1
=
__import__
(
TESTFN
)
self
.
assertEqual
(
m1
.
x
,
'original'
)
# Change the file and then reimport it
os
.
chmod
(
fname
,
0600
)
with
open
(
fname
,
'w'
)
as
f
:
f
.
write
(
"x = 'rewritten'
\
n
"
)
unload
(
TESTFN
)
m2
=
__import__
(
TESTFN
)
self
.
assertEqual
(
m2
.
x
,
'rewritten'
)
# Now delete the source file and check the pyc was rewritten
unlink
(
TESTFN
)
unload
(
TESTFN
)
m3
=
__import__
(
TESTFN
)
self
.
assertEqual
(
m3
.
x
,
'rewritten'
)
finally
:
chmod_files
(
TESTFN
)
remove_files
(
TESTFN
)
unload
(
TESTFN
)
del
sys
.
path
[
0
]
def
test_imp_module
(
self
):
def
test_imp_module
(
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
...
...
Misc/NEWS
View file @
b48c028c
...
@@ -9,6 +9,9 @@ What's New in Python 2.7.4
...
@@ -9,6 +9,9 @@ What's New in Python 2.7.4
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #6074: Ensure cached bytecode files can always be updated by the
user that created them, even when the source file is read-only.
- Issue #14783: Improve int() and long() docstrings and switch docstrings for
- Issue #14783: Improve int() and long() docstrings and switch docstrings for
unicode(), slice(), range(), and xrange() to use multi-line signatures.
unicode(), slice(), range(), and xrange() to use multi-line signatures.
...
...
Python/import.c
View file @
b48c028c
...
@@ -910,6 +910,12 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat)
...
@@ -910,6 +910,12 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat)
time_t
mtime
=
srcstat
->
st_mtime
;
time_t
mtime
=
srcstat
->
st_mtime
;
#ifdef MS_WINDOWS
/* since Windows uses different permissions */
#ifdef MS_WINDOWS
/* since Windows uses different permissions */
mode_t
mode
=
srcstat
->
st_mode
&
~
S_IEXEC
;
mode_t
mode
=
srcstat
->
st_mode
&
~
S_IEXEC
;
/* Issue #6074: We ensure user write access, so we can delete it later
* when the source file changes. (On POSIX, this only requires write
* access to the directory, on Windows, we need write access to the file
* as well)
*/
mode
|=
_S_IWRITE
;
#else
#else
mode_t
mode
=
srcstat
->
st_mode
&
~
S_IXUSR
&
~
S_IXGRP
&
~
S_IXOTH
;
mode_t
mode
=
srcstat
->
st_mode
&
~
S_IXUSR
&
~
S_IXGRP
&
~
S_IXOTH
;
#endif
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment