Clear cached files when they fail to extract or validate, refs #941
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();
|
||||
|
|
|
@ -34,8 +34,14 @@ abstract class ArchiveDownloader extends FileDownloader
|
|||
if ($this->io->isVerbose()) {
|
||||
$this->io->write(' Unpacking archive');
|
||||
}
|
||||
try {
|
||||
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…
Reference in New Issue