bytedance / bytedance/pdf-parser
fix: avoid deleting unrelated files in existing output directories
- Dominant language
- Python
- Stars
- 14
- Forks
- 9
- Avg merge
- 43m
- Merged PRs (30d)
- 1
Description
## Problem
`prepare_output_dir()` recursively deletes an existing `/` directory before each parse. The directory can contain files that were not created by the current invocation, so a normal parse command can remove unrelated user data without confirmation.
This affects current `main` at `c6478aae9ab50a13fc54c0599a0a459396c15b99` and release `0.0.5`.
## Minimal reproduction
```python
from pathlib import Path
from tempfile import TemporaryDirectory
from hi_pdf_parser.artifact_writer import prepare_output_dir
with TemporaryDirectory() as temp:
out = Path(temp) / "out"
existing = out / "report"
existing.mkdir(parents=True)
marker = existing / "keep.txt"
marker.write_text("user data", encoding="utf-8")
prepare_output_dir(out, "report")
assert marker.exists() # fails: the marker was recursively deleted
```
The same path is reached by parsing `report.pdf` when `out/report` already exists.
## Expected behavior
The command should not silently remove files it cannot identify as artifacts from the current operation. Possible policies include refusing a non-empty destination, requiring an explicit overwrite option, or replacing only known generated artifacts.
## Impact
Re-running the CLI with a shared output root can destroy unrelated files placed under a stem-named directory.
## Why there is no PR in this report
A fix changes the CLI's existing overwrite behavior and requires a maintainer decision about compatibility and the intended overwrite/recovery policy. Once that policy is chosen, it should be covered by tests for existing generated output, unrelated files, and partial previous runs.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading prepare_output_dir in hi_pdf_parser/artifact_writer.py and trace the parse path that reaches it for an existing output directory. Before changing behavior, get a maintainer decision on the overwrite policy. Done should preserve unrelated files and include tests covering existing generated output, unrelated files, and partial previous runs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100