Skip to content

fix(cli): a commit that cannot read a file lands no version - #10

Merged
adammharris merged 1 commit into
mainfrom
agent/backlog-an-unreadable-file-commits-a-partial-version
Nov 6, 2026
Merged

adammharris merged 1 commit into
mainfrom
agent/backlog-an-unreadable-file-commits-a-partial-version

Conversation

@adammharris

Copy link
Copy Markdown
Member

What changed

  • Object::try_commit is new. It takes an iterator of Results and abandons the version at the first Err, during staging, before anything is written.
  • Object::commit is now try_commit over an iterator that cannot fail. Its signature and behaviour are unchanged.
  • mocfl commit calls try_commit, so a file it cannot read stops the commit. The error message and exit code are the same as before.
  • The README's Committing section says so, and the task is marked done.

Why

mocfl commit read the tree through map_while, so an unreadable file ended the iterator early. Object::commit takes what it is given as the version's complete state, so the version landed with every path from that file onward deleted, and the failure was reported only afterwards. Running it again added another version, an unreadable first file got past the --allow-empty guard, and a first commit wrote a partial object.

Memory use is unchanged: files are still read one at a time, through the same staging loop.

Task

Closes docs/tasks/an-unreadable-file-commits-a-partial-version.md.

Verification

  • New mocfl-cli/tests/commit_unreadable.rs drives the real binary and compares the object's bytes: an object with a version (including a second failed run), a first commit, an unreadable file that sorts first, and a commit that succeeds once the file is readable. All 4 failed before the fix and pass after it.
  • Two new unit tests in mocfl/src/object.rs cover try_commit, including that nothing after the Err is asked for.
  • The task's repro now gives exit 1, ls still lists all four files, the object stays at v1 after two failed runs, validate --deep passes, and no object appears for a failed first commit.
  • Run locally, all green: cargo fmt --all --check, cargo clippy --all-targets -- -D warnings, cargo test --all-targets with OCFL_FIXTURES set to a fresh clone of OCFL/fixtures, cargo test --doc, and cargo +1.88 check --all-targets.
  • Not run locally: the rocfl validation step, because rocfl is not installed on this machine. The interop test that emits the object does pass; this PR's CI runs the rocfl step.

The new CLI tests return early if the user can read a mode-000 file (root), since they would prove nothing there. They are cfg(unix).

mocfl commit read the tree through map_while and handed the iterator to
Object::commit, which takes what it is given as the version's complete state.
A file it could not read ended the iterator early, so the version landed with
every path from that file on deleted, and only then did the command report
the failure. Run again it added another version, an unreadable first file got
past the --allow-empty guard, and a first commit wrote a partial object.

Object::try_commit takes an iterator of Results and abandons the version at
the first Err, during staging, before anything is written. commit is
try_commit over an iterator that cannot fail, and the CLI uses try_commit,
reading one file at a time as before.

Behavioural-change: mocfl commit that cannot read a file now writes nothing, where it used to land a partial version (or a partial first object) before exiting non-zero.
@adammharris
adammharris merged commit f7cd8ab into main Nov 6, 2026
3 checks passed
@adammharris
adammharris deleted the agent/backlog-an-unreadable-file-commits-a-partial-version branch November 6, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant