summaryrefslogtreecommitdiffstats
path: root/Lib/test/support/import_helper.py
diff options
context:
space:
mode:
authorJason Wilkes <notarealdeveloper@gmail.com>2022-02-08 01:09:07 (GMT)
committerGitHub <noreply@github.com>2022-02-08 01:09:07 (GMT)
commitda576e08296490e94924421af71001bcfbccb317 (patch)
treee6967cb02a5a5b512c0cd1e2a4e45a49e85744ad /Lib/test/support/import_helper.py
parent7a0486eaa98083e0407ff491872db6d7a0da2635 (diff)
downloadcpython-da576e08296490e94924421af71001bcfbccb317.zip
cpython-da576e08296490e94924421af71001bcfbccb317.tar.gz
cpython-da576e08296490e94924421af71001bcfbccb317.tar.bz2
bpo-46678: Fix Invalid cross device link in Lib/test/support/import_helper.py (GH-31204)
In [Lib/test/support/import_helper.py](https://github.com/python/cpython/blob/master/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
Diffstat (limited to 'Lib/test/support/import_helper.py')
-rw-r--r--Lib/test/support/import_helper.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/test/support/import_helper.py b/Lib/test/support/import_helper.py
index 9bce298..5201dc8 100644
--- a/Lib/test/support/import_helper.py
+++ b/Lib/test/support/import_helper.py
@@ -3,6 +3,7 @@ import _imp
import importlib
import importlib.util
import os
+import shutil
import sys
import unittest
import warnings
@@ -59,7 +60,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