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

main
Jordi Boggiano 12 years ago
parent c281315fb4
commit 07f7487c60

@ -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();

@ -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');

@ -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}
*/

Loading…
Cancel
Save