Repository navigation
fix(catalog): catalog eval receipts keep the group and mode of the files a rerun replaces #1348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
f2bc292
fix(catalog): catalog eval receipts keep the group and mode of the fi…
antonwolfy a7fcdf9
fix(catalog): a rerun receipt gets no ACL entry of the directory default
xaleryb 9abefde
fix(catalog): a failed receipt swap removes a read-only new receipt b…
antonwolfy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
dokimi/changelog.d/20261127_140000_catalog-eval-receipts-keep-group-mode.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <!-- | ||
| Copyright (C) 2026 Intel Corporation | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| --> | ||
|
|
||
| ### Fixed | ||
|
|
||
| - **`catalog eval --out-dir` keeps the group and mode of the receipts a rerun replaces** — `catalog.json`, `plan.json`, `result.json` and `report.md` were staged as new files and renamed over the previous ones, so a `0o640` receipt in a supplementary group came back `0o664` in the user's primary group (the cause of #1067 and #1165). The staged file now gets the previous receipt's mode and, where the user may give it, its group (root also the owner) before the rename, through `dokimi.atomic_write.keep_owner_group_mode`. A user who may not give the group keeps the receipt published in their own group, without an error; a receipt with no previous file keeps the umask mode as before. An access ACL the staged file inherited from the output directory's default ACL is dropped before the mode is set, so the receipt grants no named user more than the one it replaces. The previous receipts are still moved aside first and put back as they were when the swap fails, and a new receipt that took a read-only mode is made writable before that rollback removes it, as Windows refuses to unlink a read-only file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Copyright (C) 2026 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """The receipt swap of catalog eval: its rollback and a previous receipt that is a link.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.skipif(sys.platform == "win32", reason="POSIX modes and links") | ||
| def test_a_rerun_replaces_a_linked_receipt_without_taking_its_targets_mode(tmp_path): | ||
| from dokimi.commands.catalog_eval import _replace_receipts | ||
|
|
||
| out, staged, backup = tmp_path / "out", tmp_path / "new", tmp_path / "old" | ||
| for directory in (out, staged, backup): | ||
| directory.mkdir() | ||
| target = tmp_path / "target.md" | ||
| target.write_text("target", encoding="utf-8") | ||
| os.chmod(target, 0o600) | ||
| (out / "report.md").symlink_to(target) | ||
| (staged / "report.md").write_text("new", encoding="utf-8") | ||
| os.chmod(staged / "report.md", 0o644) | ||
| _replace_receipts(out, staged, backup) | ||
| assert not (out / "report.md").is_symlink() | ||
| assert (out / "report.md").read_text(encoding="utf-8") == "new" | ||
| assert oct((out / "report.md").stat().st_mode & 0o7777) == "0o644" | ||
|
|
||
|
|
||
| @pytest.mark.skipif(sys.platform == "win32", reason="POSIX modes") | ||
| def test_a_failed_swap_restores_receipts_when_the_unlink_of_a_read_only_one_is_refused(tmp_path, monkeypatch): | ||
| from dokimi.commands.catalog_eval import _replace_receipts | ||
|
|
||
| out, staged, backup = tmp_path / "out", tmp_path / "new", tmp_path / "old" | ||
| for directory in (out, staged, backup): | ||
| directory.mkdir() | ||
| for name in ("catalog.json", "plan.json"): | ||
| (out / name).write_text(f"old {name}", encoding="utf-8") | ||
| (staged / name).write_text(f"new {name}", encoding="utf-8") | ||
| os.chmod(out / "catalog.json", 0o444) | ||
| real_replace, real_unlink = os.replace, Path.unlink | ||
| failure = OSError("injected plan publication failure") | ||
|
|
||
| def replace(src, dst): | ||
| if Path(dst) == out / "plan.json" and Path(src).parent == staged: | ||
| raise failure | ||
| return real_replace(src, dst) | ||
|
|
||
| def unlink(self, missing_ok=False): | ||
| if self.exists() and not self.stat().st_mode & 0o200: # Windows refuses a read-only file | ||
| raise PermissionError(13, "read-only", str(self)) | ||
| return real_unlink(self, missing_ok=missing_ok) | ||
|
|
||
| monkeypatch.setattr("dokimi.commands.catalog_eval.os.replace", replace) | ||
| monkeypatch.setattr(Path, "unlink", unlink) | ||
| with pytest.raises(OSError) as raised: | ||
| _replace_receipts(out, staged, backup) | ||
| assert raised.value is failure | ||
| assert {p.name: p.read_text(encoding="utf-8") for p in out.iterdir()} == { | ||
| "catalog.json": "old catalog.json", "plan.json": "old plan.json"} | ||
| assert oct((out / "catalog.json").stat().st_mode & 0o7777) == "0o444" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.