浏览代码

Cache: clear cache using removeDirectory

Brandon Max 7 年之前
父节点
当前提交
24b8fea48a
共有 3 个文件被更改,包括 27 次插入4 次删除
  1. 9 0
      src/Composer/Cache.php
  2. 4 4
      src/Composer/Command/ClearCacheCommand.php
  3. 14 0
      tests/Composer/Test/CacheTest.php

+ 9 - 0
src/Composer/Cache.php

@@ -175,6 +175,15 @@ class Cache
         return false;
     }
 
+    public function clear()
+    {
+        if ($this->enabled) {
+            return $this->filesystem->removeDirectory($this->root);
+        }
+
+        return false;
+    }
+
     public function gc($ttl, $maxSize)
     {
         if ($this->enabled) {

+ 4 - 4
src/Composer/Command/ClearCacheCommand.php

@@ -42,10 +42,10 @@ EOT
         $io = $this->getIO();
 
         $cachePaths = array(
-            'cache-dir' => $config->get('cache-dir'),
-            'cache-files-dir' => $config->get('cache-files-dir'),
-            'cache-repo-dir' => $config->get('cache-repo-dir'),
             'cache-vcs-dir' => $config->get('cache-vcs-dir'),
+            'cache-repo-dir' => $config->get('cache-repo-dir'),
+            'cache-files-dir' => $config->get('cache-files-dir'),
+            'cache-dir' => $config->get('cache-dir'),
         );
 
         foreach ($cachePaths as $key => $cachePath) {
@@ -63,7 +63,7 @@ EOT
             }
 
             $io->writeError("<info>Clearing cache ($key): $cachePath</info>");
-            $cache->gc(0, 0);
+            $cache->clear();
         }
 
         $io->writeError('<info>All caches cleared.</info>');

+ 14 - 0
tests/Composer/Test/CacheTest.php

@@ -107,4 +107,18 @@ class CacheTest extends TestCase
         }
         $this->assertFileExists("{$this->root}/cached.file3.zip");
     }
+
+    public function testClearCache()
+    {
+        $this->finder
+            ->method('removeDirectory')
+            ->with($this->root)
+            ->willReturn(true);
+
+        $this->assertTrue($this->cache->clear());
+
+        for ($i = 0; $i < 3; $i++) {
+            $this->assertFileNotExists("{$this->root}/cached.file{$i}.zip");
+        }
+    }
 }