From 04834521f1298c8fee2704b1c4b1df43b655eb60 Mon Sep 17 00:00:00 2001 From: Ka Date: Tue, 19 Aug 2014 10:20:36 +0200 Subject: [PATCH] [Filesystem Component] mkdir race condition fix #11626 --- src/Symfony/Component/Filesystem/Filesystem.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index b9dc231f6a..f1a7cfba65 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -78,7 +78,14 @@ class Filesystem } if (true !== @mkdir($dir, $mode, true)) { - throw new IOException(sprintf('Failed to create %s', $dir)); + $error = error_get_last(); + if (!is_dir($dir)) { + // The directory was not created by a concurrent process. Let's throw an exception with a developer friendly error message if we have one + if ($error) { + throw new IOException(sprintf('Failed to create "%s": %s.', $dir, $error['message'])); + } + throw new IOException(sprintf('Failed to create "%s"', $dir)); + } } } }