From c502601c4bd05487a11454677acfa3b7a0ae9e85 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 28 Feb 2016 14:06:36 +0000 Subject: [PATCH] Retry on RecursiveDirectoryIterator failure to open dir, refs #4009 --- src/Composer/Util/Filesystem.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 463fac1e7..041be9e3b 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -145,7 +145,15 @@ class Filesystem */ public function removeDirectoryPhp($directory) { - $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS); + try { + $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS); + } catch (\UnexpectedValueException $e) { + // re-try once after clearing the stat cache if it failed as it + // sometimes fails without apparent reason, see https://github.com/composer/composer/issues/4009 + clearstatcache(); + usleep(100000); + $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS); + } $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); foreach ($ri as $file) {