Repository navigation
Use exclusive staging and safe lock opens for account files #1849
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -570,3 +570,26 @@ def open_(*args, **kwargs): | |
| monkeypatch.setattr(helper.urllib.request, "urlopen", open_) | ||
| with pytest.raises(TimeoutError, match="provider HTTP request timed out"): | ||
| helper._http(request, timeout=1) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("symlink", [False, True]) | ||
| def test_account_staging_preserves_colliding_path(helper, tmp_path, symlink): | ||
| path = helper.STATE / "status.json" | ||
| staged = path.with_name(f"{path.name}.{helper.os.getpid()}.{helper.threading.get_ident()}.tmp") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Staging test only checks the old temp-file name, which the new code never uses The test puts a regular file or symlink at the old |
||
| target = tmp_path / "unrelated" if symlink else staged | ||
| target.write_text("preserve") | ||
| if symlink: | ||
| staged.symlink_to(target) | ||
| helper.write_private(path, "{}") | ||
| assert path.read_text() == "{}" and target.read_text() == "preserve" | ||
|
|
||
|
|
||
| def test_account_lock_preserves_existing_file_and_rejects_symlink(helper): | ||
| lock = helper.STATE / ".lock" | ||
| lock.write_text("preserve") | ||
| with helper._locked(lock.name): | ||
| assert lock.read_text() == "preserve" | ||
| (helper.STATE / ".codex-sync.lock").symlink_to(lock) | ||
| with pytest.raises(OSError), helper._locked(".codex-sync.lock"): | ||
| pytest.fail("redirected lock opened") | ||
| assert lock.read_text() == "preserve" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Non-regular lock rejection path is untested
The new
S_ISREGcheck, together withO_NONBLOCK, guards against a FIFO or device at the lock path. No test covers it. Add a short case that createsSTATE/.lockwithos.mkfifoand expectsValueErrorfromhelper._locked('.lock'). That way a later refactor can't quietly dropO_NONBLOCKand let a FIFO hang the open.