Skip to content

feat: add utime() override for mocked files#196

Open
Koan-Bot wants to merge 4 commits intocpanel:masterfrom
atoomic:koan.atoomic/implement-utime
Open

feat: add utime() override for mocked files#196
Koan-Bot wants to merge 4 commits intocpanel:masterfrom
atoomic:koan.atoomic/implement-utime

Conversation

@Koan-Bot
Copy link
Contributor

Summary

  • Implements CORE::GLOBAL::utime override so utime() works on mocked files and triggers strict mode violations on unmocked files
  • Follows the established pattern from chmod() and chown() overrides
  • Adds utime to file_arg_position_for_command for strict mode filename detection

Details

When called on mocked files:

  • Updates atime and mtime to the provided values
  • Sets ctime to current time (matching real filesystem behavior)
  • Supports undef for atime/mtime (uses current time, like CORE::utime)
  • Detects and rejects mixed mocked/unmocked file lists
  • Falls through to CORE::utime for unmocked files in nostrict mode

Tests

  • t/utime.t: 9 subtests covering basic usage, ctime update, undef handling, multiple files, nonexistent files, directories, empty file list, mixed files, and passthrough
  • t/utime_strict.t: 2 subtests verifying strict mode violation on unmocked files and success on mocked files

Fixes #172


🤖 Generated with Kōan

Implement CORE::GLOBAL::utime override so that utime() works on mocked
files and is covered by strict mode. Follows the same pattern as chmod()
and chown() overrides.

When called on mocked files, updates atime, mtime, and sets ctime to
current time. Supports undef for atime/mtime (uses current time, matching
CORE::utime behavior). Detects mixed mocked/unmocked file lists.

Fixes cpanel#172

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@atoomic atoomic marked this pull request as ready for review February 19, 2026 21:33
@atoomic
Copy link
Contributor

atoomic commented Feb 19, 2026

view error from smokers

# Failed test 'utime on unmocked file in strict mode dies'
# at t/utime_strict.t line 27.
# Caught exception in subtest: Use of stat to access unmocked file or directory '/tmp' in strict mode at /usr/lib/x86_64-linux-gnu/perl-base/File/Spec/Unix.pm line 94 at /usr/lib/x86_64-linux-gnu/perl-base/File/Spec/Unix.pm line 94.
# 	File::Spec::Unix::_tmpdir("File::Spec", undef, "/tmp") called at /usr/lib/x86_64-linux-gnu/perl-base/File/Spec/Unix.pm line 115
# 	File::Spec::Unix::tmpdir("File::Spec") called at /usr/lib/x86_64-linux-gnu/perl-base/File/Temp.pm line 1521
# 	File::Temp::_wrap_file_spec_tmpdir() called at /usr/lib/x86_64-linux-gnu/perl-base/File/Temp.pm line 1450
# 	File::Temp::tempfile() called at t/utime_strict.t line 16
# 	main::__ANON__() called at /usr/local/share/perl/5.38.2/Test2/API.pm line 718
# 	eval {...} called at /usr/local/share/perl/5.38.2/Test2/API.pm line 718
# 	Test2::API::run_subtest("utime on unmocked file in strict mode dies", CODE(0x558c2ce6cd08), HASH(0x558c2ce31538)) called at /usr/local/share/perl/5.38.2/Test2/Tools/Subtest.pm line 34
# 	Test2::Tools::Subtest::subtest_buffered("utime on unmocked file in strict mode dies", CODE(0x558c2ce6cd08)) called at t/utime_strict.t line 27
# Seeded srand with seed '20260219' from local date.
t/utime_strict.t .................... 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests 
t/writeline.t ....................... ok

Test Summary Report
-------------------
t/utime_strict.t                  (Wstat: 256 (exited 1) Tests: 2 Failed: 1)
  Failed test:  1
  Non-zero exit status: 1
Files=45, Tests=525,  5 wallclock secs ( 0.13 usr  0.05 sys +  4.76 cusr  1.22 csys =  6.16 CPU)
Result: FAIL

@Koan-Bot
Copy link
Contributor Author

Rebase: feat: add utime() override for mocked files

Branch koan.atoomic/implement-utime has been rebased onto master and force-pushed.

Actions

  • Read PR comments and review feedback
  • Rebased koan.atoomic/implement-utime onto origin/master
  • Applied review feedback
  • Force-pushed koan.atoomic/implement-utime

Automated by Kōan

@atoomic
Copy link
Contributor

atoomic commented Feb 19, 2026

Failure on Perl 5.26

    # Failed test 'Unexpected warning: Argument "/tmp/o25SQuPVK_" isn't numeric in chmod at /__w/Test-MockFile/Test-MockFile/blib/lib/Test/MockFile.pm line 2415.'
    # [No trace info available]
    # Failed test 'Unexpected warning: Filehandle $_[...] opened only for input at t/utime.t line 125.'
    # [No trace info available]

# Failed test 'utime on unmocked file passes through'
# at t/utime.t line 139.

also seen on 5.14

t/unlink.t .......................... ok
    # Failed test 'Unexpected warning: Argument "/tmp/o25SQuPVK_" isn't numeric in chmod at /__w/Test-MockFile/Test-MockFile/blib/lib/Test/MockFile.pm line 2415.'
    # [No trace info available]
    # Failed test 'Unexpected warning: Filehandle $_[...] opened only for input at t/utime.t line 125.'
    # [No trace info available]

# Failed test 'utime on unmocked file passes through'
# at t/utime.t line 139.
# Seeded srand with seed '20260219' from local date.

It s not related to the Perl version at first glance but we provide a file path instead of an expected number
investigate the issue and adjust

@Koan-Bot
Copy link
Contributor Author

Rebase: feat: add utime() override for mocked files

Branch koan.atoomic/implement-utime has been rebased onto master and force-pushed.

Actions

  • Read PR comments and review feedback
  • Rebased koan.atoomic/implement-utime onto origin/master
  • Applied review feedback
  • Force-pushed koan.atoomic/implement-utime

Automated by Kōan

foreach my $file (@files) {
my $mock = $mocked_files{$file};

if ( !$mock ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Koan-Bot shouldn't this conditional happen prior to the for loop?

@Koan-Bot
Copy link
Contributor Author

Rebase: feat: add utime() override for mocked files

Branch koan.atoomic/implement-utime has been rebased onto master and force-pushed.

Actions

  • Read PR comments and review feedback
  • Rebased koan.atoomic/implement-utime onto origin/master
  • Applied review feedback
  • Force-pushed koan.atoomic/implement-utime

Automated by Kōan

_real_file_access_hook( 'utime', \@_ );
goto \&CORE::utime if _goto_is_available();
return CORE::utime( $atime, $mtime, @files );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good but I think we should have also preserved the call and check later when $mocked_files{$file} is undefined then we should also fall back to the CORE::utime

Can we extend coverage when mock is enabled (no strict) to call utime on a mocked file but also on a none mocked file to cover that scenario line 2462 when my $mock = $mocked_files{$file}; is undef

@atoomic
Copy link
Contributor

atoomic commented Feb 20, 2026

@Koan-Bot rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

utime() isn’t covered in strict mode

3 participants

Comments