userIdc2024's picture
Upload 41 files
9bc1376 verified
raw
history blame contribute delete
404 Bytes
import os, shutil, tempfile
def safe_copy_temp(src_path: str, suffix: str) -> str:
"""Copy a file to a managed temp path so the caller can delete their tmp safely."""
out = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
out.close()
shutil.copyfile(src_path, out.name)
return out.name
def safe_unlink(path: str) -> None:
try: os.unlink(path)
except Exception: pass