fix: avoid races in filesystem ops (#2287)
Use `exist_ok` and `missing_ok` in pathlib operations where we can.
This commit is contained in:
@@ -42,8 +42,7 @@ def main() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
dest_path = Path("docs/data/how-it-works.png")
|
dest_path = Path("docs/data/how-it-works.png")
|
||||||
if dest_path.exists():
|
dest_path.unlink(missing_ok=True)
|
||||||
dest_path.unlink()
|
|
||||||
|
|
||||||
Path(screenshot).rename(dest_path)
|
Path(screenshot).rename(dest_path)
|
||||||
|
|
||||||
|
|||||||
@@ -399,8 +399,7 @@ def build_in_directory(args: CommandLineArguments) -> None:
|
|||||||
|
|
||||||
output_dir = options.globals.output_dir
|
output_dir = options.globals.output_dir
|
||||||
|
|
||||||
if not output_dir.exists():
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
output_dir.mkdir(parents=True)
|
|
||||||
|
|
||||||
tmp_path = Path(mkdtemp(prefix="cibw-run-")).resolve(strict=True)
|
tmp_path = Path(mkdtemp(prefix="cibw-run-")).resolve(strict=True)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ CIBW_CACHE_PATH: Final[Path] = Path(
|
|||||||
def download(url: str, dest: Path) -> None:
|
def download(url: str, dest: Path) -> None:
|
||||||
print(f"+ Download {url} to {dest}")
|
print(f"+ Download {url} to {dest}")
|
||||||
dest_dir = dest.parent
|
dest_dir = dest.parent
|
||||||
if not dest_dir.exists():
|
dest_dir.mkdir(parents=True, exist_ok=True)
|
||||||
dest_dir.mkdir(parents=True)
|
|
||||||
|
|
||||||
# we've had issues when relying on the host OS' CA certificates on Windows,
|
# we've had issues when relying on the host OS' CA certificates on Windows,
|
||||||
# so we use certifi (this sounds odd but requests also does this by default)
|
# so we use certifi (this sounds odd but requests also does this by default)
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ platform = wheel.stem.split("-")[-1]
|
|||||||
name = f"spam-0.1.0-py2-none-{platform}.whl"
|
name = f"spam-0.1.0-py2-none-{platform}.whl"
|
||||||
dest = dest_dir / name
|
dest = dest_dir / name
|
||||||
dest_dir.mkdir(parents=True, exist_ok=True)
|
dest_dir.mkdir(parents=True, exist_ok=True)
|
||||||
if dest.exists():
|
dest.unlink(missing_ok=True)
|
||||||
dest.unlink()
|
|
||||||
shutil.copy(wheel, dest)
|
shutil.copy(wheel, dest)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user