Skip to content

Stdlib: touch() mtime/atime visible without prior stat (#28995) - #29011

Merged
PurHur merged 1 commit into
masterfrom
fix/28995-touch-mtime-atime
Aug 8, 2026
Merged

Stdlib: touch() mtime/atime visible without prior stat (#28995)#29011
PurHur merged 1 commit into
masterfrom
fix/28995-touch-mtime-atime

Conversation

@PurHur

@PurHur PurHur commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix touch($path, $mtime[, $atime]) so the first filemtime/fileatime after a timed touch matches Zend when there was no prior positive stat cache hit (Stdlib: touch() ignores $mtime/$atime — always uses now (ext/standard/filestat.c) #28995).
  • Root cause: VmFsTouchPure used VmStatPath::exists()VmStatCache::stat(), poisoning a positive “now” hit before host utime; invalidateNegative left that hit in place.
  • Probe existence via uncached VmStatNative::stat, and clear only the host BG stat cache after a successful host touch — do not drop VmStatCache positive entries (php-src-strict #25853).
  • Align compliance/AOT fixtures with Zend: after is_file/filemtime, either clearstatcache or use a fresh path before asserting new times; add touch_mtime_atime_no_prior_stat.phpt.

php-src: ext/standard/filestat.cPHP_FUNCTION(touch) / php_touch

Test plan

  • Issue repro VM vs Zend (3-arg + 2-arg + prior-stat stale) → both green
  • php bin/vm.php test/compliance/cases/stdlib/touch.phpt
  • php bin/vm.php test/compliance/cases/stdlib/touch_mtime_atime_no_prior_stat.phpt
  • php bin/vm.php test/compliance/cases/stdlib/touch_statcache_stale.phpt
  • vendor/bin/phpunit --filter 'TouchBuiltinTest::testVm|VmFsTouchTempnam|VmStatCacheTest::testTouch' → OK (10 tests)

AOT note: native AOT touch via FsDirJitHelper still delegates to host \touch/\fopen inside the compiled helper (#12145) and does not set times on this host (pre-existing; 1-arg create also fails). This PR fixes the VM php-src-strict gap the issue repro targets; AOT utime needs a non-host path (follow-up).

Gate snapshot: inventory OK 7248/7248; north-star5-fast ok; user_release_ready: no due to 30 stale helper-runtime units (#29003 / open PR #29005) — unrelated to this change.

Closes #28995

Made with Cursor

VmFsTouchPure used VmStatPath::exists(), which wrote a positive VmStatCache
hit before host utime — so the first filemtime/fileatime after a timed touch
returned "now". Probe via uncached VmStatNative::stat and clear only the host
BG cache after a successful touch; keep VmStatCache positive hits until
clearstatcache (#25853).
@PurHur
PurHur merged commit 208a275 into master Aug 8, 2026
1 check failed
@PurHur
PurHur deleted the fix/28995-touch-mtime-atime branch August 8, 2026 12:12
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.

Stdlib: touch() ignores $mtime/$atime — always uses now (ext/standard/filestat.c)

1 participant