Files
claude-config/bin/task_bench/bugs/scratch_copy.py
T

25 lines
1.0 KiB
Python

"""A copy of a tree for a mutation tool to run in, so that what the tool writes there goes with the copy."""
import os
import shutil
from failure import Failure
from mutate_changes.tool_process import remove, scratch_folder
def scratch_copy(top: str) -> tuple[str, str] | Failure:
"""A new scratch folder in top, and in it a copy of top's other entries, links kept as links: the two folders' paths. The
caller removes the scratch folder.
A mutation tool leaves files where it runs: its cache, and each log the project's config asks for, which tells where every
mutant is. A bug's tree is a copy of top, so the tool runs in this copy and top stays as it was."""
scratch = scratch_folder(top)
if isinstance(scratch, Failure):
return scratch
copy = os.path.join(scratch, "copy")
try:
shutil.copytree(top, copy, symlinks=True, ignore=shutil.ignore_patterns(os.path.basename(scratch)))
except OSError as failure:
remove(scratch)
return Failure(f"could not copy {top} into {scratch}: {failure}")
return scratch, copy