mirror of
https://github.com/python/cpython.git
synced 2026-02-13 19:04:37 +00:00
bpo-46678: Fix Invalid cross device link in Lib/test/support/import_helper.py (GH-31204) (GH-31207)
In `Lib/test/support/import_helper.py`, the function `make_legacy_pyc` makes a call to `os.rename` which can fail when the source and target live on different devices. This happens (for example) when `PYTHONPYCACHEPREFIX` is set to a directory anywhere on disk, while a ramdisk is mounted on `/tmp` (the latter of which is the default on various Linux distros). Replacing `os.rename` with `shutil.move` fixes this.
Automerge-Triggered-By: GH:brettcannon
(cherry picked from commit da576e0829)
Co-authored-by: Jason Wilkes <notarealdeveloper@gmail.com>
This commit is contained in:
parent
5b58db7529
commit
c2735b75af
2 changed files with 5 additions and 1 deletions
|
|
@ -2,6 +2,7 @@
|
|||
import importlib
|
||||
import importlib.util
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import unittest
|
||||
import warnings
|
||||
|
|
@ -58,7 +59,7 @@ def make_legacy_pyc(source):
|
|||
pyc_file = importlib.util.cache_from_source(source)
|
||||
up_one = os.path.dirname(os.path.abspath(source))
|
||||
legacy_pyc = os.path.join(up_one, source + 'c')
|
||||
os.rename(pyc_file, legacy_pyc)
|
||||
shutil.move(pyc_file, legacy_pyc)
|
||||
return legacy_pyc
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
The function ``make_legacy_pyc`` in ``Lib/test/support/import_helper.py`` no
|
||||
longer fails when ``PYTHONPYCACHEPREFIX`` is set to a directory on a
|
||||
different device from where tempfiles are stored.
|
||||
Loading…
Add table
Add a link
Reference in a new issue