diff options
author | Timo Kaufmann <timokau@zoho.com> | 2019-07-01 20:01:19 +0200 |
---|---|---|
committer | Frederik Rietdijk <freddyrietdijk@fridh.nl> | 2019-07-03 08:40:51 +0200 |
commit | 9db3a5869ee882787497a8d762cce99375606e62 (patch) | |
tree | a412f0b100f45d397364d04b10d347af383a41e9 /pkgs/development/interpreters | |
parent | 75aee3cfdba140f4d5030b6a143d3259dd1fe0a1 (diff) | |
download | nixlib-9db3a5869ee882787497a8d762cce99375606e62.tar nixlib-9db3a5869ee882787497a8d762cce99375606e62.tar.gz nixlib-9db3a5869ee882787497a8d762cce99375606e62.tar.bz2 nixlib-9db3a5869ee882787497a8d762cce99375606e62.tar.lz nixlib-9db3a5869ee882787497a8d762cce99375606e62.tar.xz nixlib-9db3a5869ee882787497a8d762cce99375606e62.tar.zst nixlib-9db3a5869ee882787497a8d762cce99375606e62.zip |
python2: backport fix for pyc race condition
This is python bug https://bugs.python.org/issue13146. Fixed since python 3.4. It makes pyc creation atomic, preventing a race condition. The patch has been rebased on our deterministic build patch. It wasn't backported to python 2.7 because there was a complaint about changed semantics. Since files are now created in a temporary directory and then moved, symlinks will be overridden. See https://bugs.python.org/issue17222. That is an edge-case however. Ubuntu and debian have backported the fix in 2013 already, making it mainstream enough for us to adopt.
Diffstat (limited to 'pkgs/development/interpreters')
-rw-r--r-- | pkgs/development/interpreters/python/cpython/2.7/atomic_pyc.patch | 41 | ||||
-rw-r--r-- | pkgs/development/interpreters/python/cpython/2.7/default.nix | 6 |
2 files changed, 47 insertions, 0 deletions
diff --git a/pkgs/development/interpreters/python/cpython/2.7/atomic_pyc.patch b/pkgs/development/interpreters/python/cpython/2.7/atomic_pyc.patch new file mode 100644 index 000000000000..56c75cbdeeaf --- /dev/null +++ b/pkgs/development/interpreters/python/cpython/2.7/atomic_pyc.patch @@ -0,0 +1,41 @@ +diff --git a/Lib/py_compile.py b/Lib/py_compile.py +index 978da73..3559eb9 100644 +--- a/Lib/py_compile.py ++++ b/Lib/py_compile.py +@@ -120,16 +120,27 @@ def compile(file, cfile=None, dfile=None, doraise=False): + return + if cfile is None: + cfile = file + (__debug__ and 'c' or 'o') +- with open(cfile, 'wb') as fc: +- fc.write('\0\0\0\0') +- if "DETERMINISTIC_BUILD" in os.environ: ++ # Atomically write the pyc/pyo file. Issue #13146. ++ # id() is used to generate a pseudo-random filename. ++ path_tmp = '{}.{}'.format(cfile, id(cfile)) ++ try: ++ with open(path_tmp, 'wb') as fc: + fc.write('\0\0\0\0') +- else: +- wr_long(fc, timestamp) +- marshal.dump(codeobject, fc) +- fc.flush() +- fc.seek(0, 0) +- fc.write(MAGIC) ++ if "DETERMINISTIC_BUILD" in os.environ: ++ fc.write('\0\0\0\0') ++ else: ++ wr_long(fc, timestamp) ++ marshal.dump(codeobject, fc) ++ fc.flush() ++ fc.seek(0, 0) ++ fc.write(MAGIC) ++ os.rename(path_tmp, cfile) ++ except OSError: ++ try: ++ os.unlink(path_tmp) ++ except OSError: ++ pass ++ raise + + def main(args=None): + """Compile several source files. diff --git a/pkgs/development/interpreters/python/cpython/2.7/default.nix b/pkgs/development/interpreters/python/cpython/2.7/default.nix index e7d07b9ad1c0..1503c221bdd4 100644 --- a/pkgs/development/interpreters/python/cpython/2.7/default.nix +++ b/pkgs/development/interpreters/python/cpython/2.7/default.nix @@ -79,6 +79,12 @@ let sha256 = "0l9rw6r5r90iybdkp3hhl2pf0h0s1izc68h5d3ywrm92pq32wz57"; }) + # Fix race-condition during pyc creation. Has a slight backwards + # incompatible effect: pyc symlinks will now be overridden + # (https://bugs.python.org/issue17222). Included in python >= 3.4, + # backported in debian since 2013. + # https://bugs.python.org/issue13146 + ./atomic_pyc.patch ] ++ optionals (x11Support && stdenv.isDarwin) [ ./use-correct-tcl-tk-on-darwin.patch ] ++ optionals stdenv.isLinux [ |