Skip to content

fix: extract _check_open_perms and fix dead elsif in __sysopen#339

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
atoomic:koan.atoomic/extract-open-perms-helper
Draft

fix: extract _check_open_perms and fix dead elsif in __sysopen#339
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
atoomic:koan.atoomic/extract-open-perms-helper

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

What

Extract the permission-check block into _check_open_perms() and fix the dead elsif branch in __sysopen.

Why

The same permission-check pattern was copy-pasted 3 times across __open, _io_file_mock_open, and __sysopen. In __sysopen, the elsif branch for checking parent-dir write perms on new file creation was unreachable dead code — O_CREAT sets contents to '' before the permission check runs, so contents is always defined by that point. This means sysopen($fh, '/protected/new', O_WRONLY|O_CREAT) silently bypasses parent-dir permission enforcement that open($fh, '>', '/protected/new') correctly applies (Closes #329).

Three independent copies also guarantee future drift (Closes #330).

How

  • Track $is_new = !defined $mock_file->{'contents'} before O_CREAT populates contents
  • Extract _check_open_perms($mock, $path, $rw, $is_new, $func, @args) as the single source of truth
  • All three call sites reduce to one-liners

Testing

  • New subtest in t/perms.t: verifies sysopen O_CREAT on a non-existent file in a 0555 directory returns EACCES
  • All existing tests pass: perms.t, sysopen.t, open.t, autodie_sysopen.t, autodie_compat.t

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant