fix(cli): reject invalid scan roots - #91
Conversation
Validate root paths before the scanner starts so a typo cannot look like a successful empty disk report. Keep the check in the CLI because inaccessible descendants remain a recoverable scanner concern. Signed-off-by: eunwoo song <presentsong@naver.com>
|
Thanks @be-student! |
Muawiya-contact
left a comment
There was a problem hiding this comment.
Welcome, and thanks for this! 🙌
The fix is right and the tests cover both cases. Two things before it can go in:
- Needs a rebase. #78 touched the same parts of
main.rsafter you opened this. - After rebasing, move your changelog line up to
[Unreleased]. We shipped v0.2.0 today, so it currently lands inside the released section and git won't warn you.
One optional idea: try_exists() instead of exists(), so an unreadable root doesn't report as missing.
Ping me when it's rebased.
|
Rebased via a merge with current main and moved the changelog entry to Unreleased. I also adopted |
Muawiya-contact
left a comment
There was a problem hiding this comment.
Rebase and changelog both sorted, and thanks for taking the try_exists idea. Ran it here: fmt, clippy and all tests pass.
One last thing, and it's a one-liner. try_exists()? propagates the raw io error, so the path drops out of the message:
$ diskern scan /nope
Error: scan root does not exist: /nope
$ diskern scan /etc/hosts/inner
Error: Not a directory (os error 20)
The second one doesn't say which root, or that it's about a root at all. With several roots on the command line you can't tell which one failed. A .with_context(|| format!("could not check scan root '{}'", root.display()))? gets it back.
Then this is good to go.
Closes #82
What & why
diskern scanpreviously accepted no roots and silently treated a nonexistent root as a successful empty scan. That made a path typo indistinguishable from a genuinely empty result, especially in JSON automation.This makes clap require at least one root and validates each root before calling the scanner. Descendant walk errors remain recoverable inside the scanner; only invalid entry roots fail at the CLI boundary. Both failures now return nonzero exits with actionable messages.
Validation
cargo fmt --all --checkcargo clippy -p diskern-core -p diskern-cli --all-targets -- -D warningscargo test -p diskern-core -p diskern-cli(59 passed)Checklist