Skip to content

fix: IO::File handle tracking and timestamps in _io_file_mock_open#392

Draft
Koan-Bot wants to merge 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/fix-io-file-handle-tracking
Draft

fix: IO::File handle tracking and timestamps in _io_file_mock_open#392
Koan-Bot wants to merge 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/fix-io-file-handle-tracking

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented May 6, 2026

What

Fix two bugs in _io_file_mock_open (the IO::File->open() code path) found during deep audit.

Why

_io_file_mock_open diverged from __open/__sysopen in two ways:

  1. Handle tracking: Stored handles in $mock->{'fh'} (singular) instead of the {'fhs'} array that __open/__sysopen use. This meant multiple IO::File handles to the same file overwrote each other's tracking, CLOSE didn't clean up properly, and handle-based operations like truncate($fh, N) couldn't resolve IO::File handles.

  2. Missing timestamps: Didn't update POSIX timestamps on file creation (atime/mtime/ctime) or truncation (mtime/ctime), and didn't update parent directory mtime. The __open path has had this logic since PR fix: set realistic nlink and unique inode defaults #259.

How

  • Changed _io_file_mock_open to use {'fhs'} array pattern matching __open/__sysopen
  • Added $was_new tracking and timestamp update logic mirroring __open

Testing

New t/io_file_handle_tracking.t with 18 assertions:

  • Multiple IO::File handles to same mock
  • Handle tracked in fhs array (not singular fh)
  • CLOSE cleans up from fhs
  • Write + reopen lifecycle
  • Creation timestamp updates
  • Truncation timestamp updates

Full test suite passes locally.


🤖 Generated with Claude Code


Quality Report

Changes: 3 files changed, 161 insertions(+), 4 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

…_open

Two bugs found via deep audit:

1. _io_file_mock_open stored file handles in $mock->{'fh'} (singular)
   while __open/__sysopen use $mock->{'fhs'} (array). This meant:
   - Multiple IO::File handles to same file overwrote each other
   - CLOSE didn't clean up (it only removes from 'fhs')
   - Handle-based operations (truncate, etc.) couldn't find IO::File handles

2. _io_file_mock_open was missing POSIX timestamp updates that __open has:
   - New file creation: atime/mtime/ctime not set
   - Truncation of existing file: mtime/ctime not updated
   - Parent directory mtime not updated on file creation

New test file with 18 assertions covering handle tracking, cleanup,
multiple handles, write+reopen, and both timestamp scenarios.

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