Skip to content

Commit 92358a4

Browse files
fix: prevent filename collisions in Save All
When multiple input files share the same stem (e.g. dir1/report.pdf and dir2/report.docx), append _1, _2, etc. to avoid silent overwrites. Co-Authored-By: rohandevin5@outlook.com <bossincrypto@gmail.com>
1 parent 0acd51b commit 92358a4

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

app/ui.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,15 @@ def _save_all(self):
377377
return
378378

379379
count = 0
380+
seen: dict[str, int] = {}
380381
for result in done:
381-
name = Path(os.path.basename(result.file_path)).stem + ".md"
382+
stem = Path(os.path.basename(result.file_path)).stem
383+
if stem in seen:
384+
seen[stem] += 1
385+
name = f"{stem}_{seen[stem]}.md"
386+
else:
387+
seen[stem] = 0
388+
name = f"{stem}.md"
382389
out_path = os.path.join(directory, name)
383390
with open(out_path, "w", encoding="utf-8") as fh:
384391
fh.write(result.markdown)

0 commit comments

Comments
 (0)