Skip to content

Commit bb97903

Browse files
committed
bug #11726 [Filesystem Component] mkdir race condition fix #11626 (kcassam)
This PR was squashed before being merged into the 2.3 branch (closes #11726). Discussion ---------- [Filesystem Component] mkdir race condition fix #11626 [Filesystem Component] Fix mkdir race condition | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11626 | License | MIT | Doc PR | none Commits ------- 0483452 [Filesystem Component] mkdir race condition fix #11626
2 parents 8990ac6 + 0483452 commit bb97903

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,14 @@ public function mkdir($dirs, $mode = 0777)
7878
}
7979

8080
if (true !== @mkdir($dir, $mode, true)) {
81-
throw new IOException(sprintf('Failed to create %s', $dir));
81+
$error = error_get_last();
82+
if (!is_dir($dir)) {
83+
// The directory was not created by a concurrent process. Let's throw an exception with a developer friendly error message if we have one
84+
if ($error) {
85+
throw new IOException(sprintf('Failed to create "%s": %s.', $dir, $error['message']));
86+
}
87+
throw new IOException(sprintf('Failed to create "%s"', $dir));
88+
}
8289
}
8390
}
8491
}

0 commit comments

Comments
 (0)