dm2-cli: low-severity batch (extract/render --all leave stale files in a reused output dir; broken-pipe panic on truncated stdout) #244

Closed
opened 2026-07-16 08:31:03 +02:00 by jqueuniet · 0 comments
jqueuniet commented 2026-07-16 08:31:03 +02:00 (Migrated from codeberg.org)

Two low-severity dm2-cli behaviours.

1. extract / render --all never clear or guard a pre-populated output dir

crates/dm2-cli/src/commands/extract.rs has no non-empty-output-directory check,
unlike repack (crates/dm2-cli/src/commands/repack.rs:278-305), which guards a
non-empty out behind --force and prunes stale canonical filenames before
copying. Reproduced:

$ mkdir out && touch out/leftover_from_before.bin
$ dm2 extract --out out --sfx fixtures/dos-en/graphics.dat
graphics.dat: extracted 5624 entries ...
$ ls out | grep leftover
leftover_from_before.bin      # still there, untouched, unmentioned

Re-running extract (e.g. with a narrower --category/--type filter, or
against a smaller archive) into the same directory silently leaves prior-run
files behind, with no warning and no count discrepancy — a user diffing or
archiving the output directory can mistake stale leftovers for current data.
Nothing in --help/README/docs states the reuse-vs-replace policy for the three
directory-writing commands; only repack has one. Fix: either document the
append/overwrite-only semantics explicitly, or give extract (and render --all) the same non-empty-dir guard behind the existing --force convention.

2. Broken-pipe panic on truncated stdout

Piping a command's output into a reader that closes early panics:

$ dm2 info fixtures/dos-en/saves/sksave0.dat | head -3
...
thread 'main' panicked at library/std/.../stdio.rs:1166:9:
failed printing to stdout: Broken pipe (os error 32)

This is the default Rust SIGPIPE-ignored behaviour; any dm2 … | head/| less
that the user quits early prints a panic + backtrace note. Cosmetic but noisy
for a CLI meant to be scripted against. Fix: reset the SIGPIPE disposition to
default at startup, or treat ErrorKind::BrokenPipe on stdout as a clean exit.

Two low-severity dm2-cli behaviours. ## 1. `extract` / `render --all` never clear or guard a pre-populated output dir `crates/dm2-cli/src/commands/extract.rs` has no non-empty-output-directory check, unlike `repack` (crates/dm2-cli/src/commands/repack.rs:278-305), which guards a non-empty `out` behind `--force` and prunes stale canonical filenames before copying. Reproduced: ``` $ mkdir out && touch out/leftover_from_before.bin $ dm2 extract --out out --sfx fixtures/dos-en/graphics.dat graphics.dat: extracted 5624 entries ... $ ls out | grep leftover leftover_from_before.bin # still there, untouched, unmentioned ``` Re-running `extract` (e.g. with a narrower `--category`/`--type` filter, or against a smaller archive) into the same directory silently leaves prior-run files behind, with no warning and no count discrepancy — a user diffing or archiving the output directory can mistake stale leftovers for current data. Nothing in `--help`/README/docs states the reuse-vs-replace policy for the three directory-writing commands; only `repack` has one. Fix: either document the append/overwrite-only semantics explicitly, or give `extract` (and `render --all`) the same non-empty-dir guard behind the existing `--force` convention. ## 2. Broken-pipe panic on truncated stdout Piping a command's output into a reader that closes early panics: ``` $ dm2 info fixtures/dos-en/saves/sksave0.dat | head -3 ... thread 'main' panicked at library/std/.../stdio.rs:1166:9: failed printing to stdout: Broken pipe (os error 32) ``` This is the default Rust SIGPIPE-ignored behaviour; any `dm2 … | head`/`| less` that the user quits early prints a panic + backtrace note. Cosmetic but noisy for a CLI meant to be scripted against. Fix: reset the SIGPIPE disposition to default at startup, or treat `ErrorKind::BrokenPipe` on stdout as a clean exit.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jqueuniet/dm2-tools#244
No description provided.