Skip to content

Commit 09e13d6

Browse files
cataphractclaude
andcommitted
Fix parallel test race condition in lib.inc temp dir creation
tempnam(__DIR__, '.tmp') + unlink + mkdir has a TOCTOU window: after unlink, another parallel worker's tempnam can claim the same name. With all tests sharing __DIR__ (the run-tests --temp-source/target dir), this reliably causes "File exists" collisions on Windows. Use sys_get_temp_dir() + PID + uniqid() instead: these together make collision impossible, so no retry loop is needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2d00d90 commit 09e13d6

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

tests/lib.inc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
function get_temp_dir() {
44
static $dir;
55
if (!$dir) {
6-
do {
7-
$dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR
8-
. 'phpla_' . getmypid() . '_' . uniqid();
9-
} while (!@mkdir($dir, 0700));
6+
$dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR
7+
. 'phpla_' . getmypid() . '_' . uniqid();
8+
mkdir($dir, 0700);
109

1110
register_shutdown_function(function() use ($dir) {
1211
$files = new RecursiveIteratorIterator(

0 commit comments

Comments
 (0)