refactor: simplify file deletion using Path.unlink(missing_ok=True)

This commit is contained in:
Tsvika Shapira 2025-12-25 19:12:57 +02:00
parent 52661e5b5c
commit fedb4c1285
3 changed files with 7 additions and 11 deletions

View File

@ -348,8 +348,7 @@ num_workers = 4
output_file = get_base_dir() / "identity_conversations.jsonl"
# Wipe the file clean first to reset it
if output_file.exists():
output_file.unlink()
output_file.unlink(missing_ok=True)
print(f"Saving to {output_file}")
# Use ThreadPoolExecutor to generate conversations in parallel

View File

@ -92,11 +92,10 @@ def download_single_file(index):
print(f"Attempt {attempt}/{max_attempts} failed for {filename}: {e}")
# Clean up any partial files
for path in [Path(str(filepath) + ".tmp"), filepath]:
if path.exists():
try:
path.unlink()
except:
pass
try:
path.unlink(missing_ok=True)
except:
pass
# Try a few times with exponential backoff: 2^attempt seconds
if attempt < max_attempts:
wait_time = 2 ** attempt

View File

@ -363,12 +363,10 @@ class Report:
# Remove section files
for file_name in EXPECTED_FILES:
file_path = self.report_dir / file_name
if file_path.exists():
file_path.unlink()
file_path.unlink(missing_ok=True)
# Remove report.md if it exists
report_file = self.report_dir / "report.md"
if report_file.exists():
report_file.unlink()
report_file.unlink(missing_ok=True)
# Generate and write the header section with start timestamp
header_file = self.report_dir / "header.md"
header = generate_header()