Message145413
| Author |
neologix |
| Recipients |
brett.cannon, ncoghlan, neologix, pitrou, r.david.murray, vstinner |
| Date |
2011年10月12日.16:37:57 |
| SpamBayes Score |
2.0595858e-11 |
| Marked as misclassified |
No |
| Message-id |
<1318437478.07.0.163853157813.issue13146@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
> Here is a patch for import.c.
Looks good to me.
> This new patch also fixes importlib.
"""
path_tmp = path + '.tmp'
with _io.FileIO(path_tmp, 'wb') as file:
file.write(data)
_os.rename(path_tmp, path)
"""
I don't know exactly the context in which this code runs, but you can have a corruption if multiple processes try to write the bytecode file at the same time, since they'll all open the .tmp file: it should be opened with O_EXCL.
Also, as a side note, I'm wondering whether this type of check:
"""
if not sys.platform.startswith('win'):
# On POSIX-like platforms, renaming is atomic
"""
couldn't be rewritten as
"""
if os.name == 'posix':
# On POSIX-like platforms, renaming is atomic
"""
Fox example, does OS-X report as POSIX? |
|