fix: extract _check_open_perms and fix dead elsif in __sysopen#339
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: extract _check_open_perms and fix dead elsif in __sysopen#339Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
The permission-check block was copy-pasted three times across __open, _io_file_mock_open, and __sysopen. In __sysopen, the elsif branch (parent-dir write check for new file creation) was unreachable because O_CREAT sets contents before the check runs. Extract _check_open_perms() as a single source of truth. In __sysopen, track $is_new before O_CREAT populates contents so the helper correctly enforces parent-dir permissions on file creation. Closes cpan-authors#329 Closes cpan-authors#330 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Extract the permission-check block into
_check_open_perms()and fix the deadelsifbranch in__sysopen.Why
The same permission-check pattern was copy-pasted 3 times across
__open,_io_file_mock_open, and__sysopen. In__sysopen, theelsifbranch for checking parent-dir write perms on new file creation was unreachable dead code —O_CREATsetscontentsto''before the permission check runs, socontentsis always defined by that point. This meanssysopen($fh, '/protected/new', O_WRONLY|O_CREAT)silently bypasses parent-dir permission enforcement thatopen($fh, '>', '/protected/new')correctly applies (Closes #329).Three independent copies also guarantee future drift (Closes #330).
How
$is_new = !defined $mock_file->{'contents'}beforeO_CREATpopulates contents_check_open_perms($mock, $path, $rw, $is_new, $func, @args)as the single source of truthTesting
t/perms.t: verifiessysopen O_CREATon a non-existent file in a 0555 directory returns EACCESperms.t,sysopen.t,open.t,autodie_sysopen.t,autodie_compat.t🤖 Generated with Claude Code