1
0
Fork 0

Clear cached files when they fail to extract or validate, refs #941

pull/1388/head
Jordi Boggiano 2012-12-05 10:10:54 +01:00
parent c281315fb4
commit 07f7487c60
3 changed files with 26 additions and 1 deletions

View File

@ -104,6 +104,16 @@ class Cache
return false;
}
public function remove($file)
{
$file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
if ($this->enabled && file_exists($this->root . $file)) {
return unlink($this->root . $file);
}
return false;
}
public function gc($ttl)
{
$expire = new \DateTime();

View File

@ -35,7 +35,13 @@ abstract class ArchiveDownloader extends FileDownloader
$this->io->write(' Unpacking archive');
}
try {
$this->extract($fileName, $path);
try {
$this->extract($fileName, $path);
} catch (\Exception $e) {
// remove cache if the file was corrupted
parent::clearCache($package, $path);
throw $e;
}
if ($this->io->isVerbose()) {
$this->io->write(' Cleaning up');

View File

@ -121,10 +121,19 @@ class FileDownloader implements DownloaderInterface
} catch (\Exception $e) {
// clean up
$this->filesystem->removeDirectory($path);
$this->clearCache($package, $path);
throw $e;
}
}
protected function clearCache(PackageInterface $package, $path)
{
if ($this->cache) {
$fileName = $this->getFileName($package, $path);
$this->cache->remove($this->getCacheKey($package));
}
}
/**
* {@inheritDoc}
*/