Browse Source

Fix case where touch() fails due to incorrect ownership, fixes #4070

Jordi Boggiano 9 years ago
parent
commit
b181822e90
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/Composer/Cache.php

+ 7 - 1
src/Composer/Cache.php

@@ -136,7 +136,13 @@ class Cache
     {
         $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
         if ($this->enabled && file_exists($this->root . $file)) {
-            touch($this->root . $file, filemtime($this->root . $file), time());
+            try {
+                touch($this->root . $file, filemtime($this->root . $file), time());
+            } catch (\ErrorException $e) {
+                // fallback in case the above failed due to incorrect ownership
+                // see https://github.com/composer/composer/issues/4070
+                touch($this->root . $file);
+            }
 
             if ($this->io->isDebug()) {
                 $this->io->writeError('Reading '.$this->root . $file.' from cache');