Skip to content

fix: set ownership to mock user on file/dir creation#367

Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-created-file-ownership
Draft

fix: set ownership to mock user on file/dir creation#367
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-created-file-ownership

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

What

Newly created files, directories, and symlinks now inherit uid/gid from the mock user when set_user() is active.

Why

POSIX mandates that open(O_CREAT), mkdir(2), and symlink(2) set the new object's ownership to the effective uid/gid. Previously, mock objects retained the real process uid/gid regardless of the mock user identity, making permission-sensitive tests unreliable.

How

Added _apply_ownership($mock) helper that sets uid/gid from $_mock_uid/@_mock_gids when a mock user is active (no-op otherwise). Called at file creation points in __open, __sysopen (O_CREAT), __mkdir, and __symlink. Opening or truncating existing files is unaffected.

Testing

New test file t/ownership_on_create.t covers:

  • open(">")/open(">>") creating files
  • sysopen(O_CREAT) creating files
  • mkdir() creating directories
  • symlink() creating symlinks
  • No-op when set_user() is not active
  • Existing files preserve original ownership on open/truncate

Full suite passes (1594 tests, only pre-existing fh-ref-leak.t failure on this Perl).


🤖 Generated with Claude Code

When set_user() is active, newly created files, directories, and
symlinks now get uid/gid from the mock user identity instead of
keeping the real process uid/gid. This matches POSIX behavior where
open(O_CREAT), mkdir(2), and symlink(2) set ownership to the
effective uid/gid.

Affected operations: open (write-create), sysopen (O_CREAT), mkdir,
symlink. Existing files opened for read/write are not affected.

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

Development

Successfully merging this pull request may close these issues.

1 participant