Repository navigation
fix(catalog): catalog eval receipts keep the group and mode of the files a rerun replaces - #1348
Conversation
…les a rerun replaces (intel#1220) _replace_receipts renamed freshly staged files over the previous catalog.json, plan.json, result.json and report.md, so a 0o640 receipt in a supplementary group came back 0o664 in the user's primary group. The staged file now gets the previous receipt's mode and, where the user may, its group (root also the owner) before the rename, through the new dokimi.atomic_write.keep_owner_group_mode, which reuses _keep_owner_and_group and sets the mode last. The move-aside rollback is unchanged, a receipt with no previous file keeps the umask mode, and a group the user may not give is skipped without an error. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1348 +/- ##
==========================================
+ Coverage 96.19% 96.21% +0.02%
==========================================
Files 499 509 +10
Lines 66465 67786 +1321
Branches 11542 11767 +225
==========================================
+ Hits 63933 65222 +1289
- Misses 1563 1578 +15
- Partials 969 986 +17
🚀 New features to boost your workflow:
|
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s). CI at Test notes (3)
Review details
|
The staged receipt inherits an access ACL from the output directory's default ACL; the chmod that restores the old mode widened its mask, so a named user the old receipt never granted could read it. Drop the inherited access ACL before the chmod, as _publish does. Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
|
Mutation of changed lines13 mutants of the lines this PR changes, at 9abefde: 8 killed, 5 survived, 0 waived, 0 inconclusive, 0 timed out, 0 errors, 0 not run. A survivor is a change to that line that the tests covering it do not notice: add an assertion that fails on it or, if the change cannot alter behaviour, put
Warn-only: a survivor does not fail the job yet. Updated on every push; the full report is in the ci run summary. |
…efore restoring the old ones A staged receipt now takes the mode of the one it replaces, so a read-only previous receipt makes a read-only new one. Windows refuses to unlink a read-only file, so the rollback of a later failed rename stopped with _RollbackFailed and left a partial set. The rollback now makes the placed receipt writable before it removes it. Settles the review thread on catalog_eval.py:122. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@xaleryb (#1348 (comment)): The ACL thread is already fixed by a7fcdf9 (see 4722748478). The Windows thread did not reproduce on Linux as the comment says, since Linux unlinks a read-only file; it is fixed in 9abefde against a simulated Windows refusal (see 4722748483). |
xaleryb
left a comment
There was a problem hiding this comment.
Approved on 9abefde. A catalog eval rerun keeps the mode and group of the receipts it replaces, a failed rerun leaves them intact, and no inherited default ACL widens access (our commit); the author's last commit makes a read-only new receipt writable before the rollback removes it, which settles the Windows thread. Checks are green on this head. Windows smoke had not started (the hosted Windows queue was stuck); every other check passed.
Summary
#1220:
catalog eval --out-dirstages its four receipts (catalog.json,plan.json,result.json,report.md) as new files and_replace_receiptsrenames them over the previous ones, so a rerun loses their group and mode, the same cause as #1067 and #1165. Onmain, without/catalog.jsonat0o640in a supplementary group (4) and a newly stagedcatalog.json,_replace_receipts(out, staged, backup)leaves group 1000 and mode0o644(the staged file's mode); a0o600report.mdcomes back0o644.Fix option taken: the first one the issue lists. The old receipt's
statis read once it is moved aside, and the staged file gets its mode and, where the user may, its group before the rename. This keeps the move-aside rollback, which the existing tests pin, and the directory is still never renamed or removed. Staging withwrite_text_atomicstraight intooutwould change what those rollback tests observe and what_write_errorleaves behind.Closes #1220
Changes
dokimi/atomic_write.py: newkeep_owner_group_mode(path, old). It gives a file the user owns the group (root: also the owner) ofoldthrough_keep_owner_and_group, then its mode withos.chmod, last, as_publishdoes. A user who may not give the group keeps the file's own group without an error.dokimi/commands/catalog_eval.py:_replace_receiptscalls it through a small_keep_previous_ownerfor each staged name whose previous receipt was moved aside. A name with no previous file, or a previous one that is not a regular file, is placed as before (umask mode).keep_owner_group_modealso removes thesystem.posix_acl_accessthe staged file inherited from the output directory's default ACL before theos.chmod, as_publishdoes, so the chmod's mask does not activate a named user the previous receipt never granted.dokimi/commands/catalog_eval.py: the rollback removes a placed receipt through_unlink_receipt, which makes a read-only one writable first, as Windows refuses to unlink a read-only file and a previous read-only receipt now gives a read-only new one.tests/test_catalog_eval_cli.py: group and mode kept (skips when the user has no supplementary group), mode alone, a refused group change publishes in the user's own group with the mode kept, no inherited ACL entry on the new receipt, and a first run keeps the staged mode.tests/test_catalog_eval_rollback.py: a failed swap restores the previous receipts when the unlink of a read-only new one is refused, and a previous receipt that is a link is replaced without taking its target's mode.Risk
A rerun now leaves the receipts with the group and mode the previous ones had, not the umask mode: a receipt made read-only or group-private stays so. The rollback still restores the old inodes, which kept their group and mode, and
_RollbackFailedstill names the kept backup; it now also clears the read-only mode of a new receipt before removing it. As root, a refused chown or chmod of a staged receipt raises and the previous receipts are put back, where the file was left in the root's group before. Open PRs #1190, #1247 and #1324 also changecatalog_eval.py, but only itsInputErrorimport line and_emit; this PR adds one import line and_keep_previous_owner, so a merge with them is trivial.Testing
On a Linux review host, at
9abefde6(onmain16738246):make ci-local: 38 passed, 0 failed, 15 skipped (docker smoke, pinned Claude Code, jobs conditional on a PR, matrix legs, conda-forge, atheris fuzz, semgrep). 30121 tests passed, 23 skipped; with the catalog eval tests,catalog_eval.pyhas no uncovered or partial changed line.main's code the new tests fail:3 failed, 2 passedof the selected five; the first assertion is(1000, '0o644') == (4, '0o640')for the issue's repro.os.chmodfails the group and mode, mode and refused-group tests; dropping the group change fails the group and mode test ((1000, '0o640') == (4, '0o640')); making a first run chmod the staged file to0o600fails the first-run test; calling the plainunlinkin the rollback again makes the swap raise_RollbackFailed([Errno 13] read-only) instead of the injected failure, and dropping the regular-file check fails the linked-receipt test.Path.unlink), and a run as root.Open questions
None.
Revert
A plain revert restores the old behaviour (rerun receipts get the umask mode and the user's primary group). Nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)