1
0
Fork 0

Add a way for FileDownloader subclasses to add paths to the cleanup stage

pull/8952/head
Jordi Boggiano 2020-06-05 08:30:59 +02:00
parent cda9849d19
commit d5286d0cb8
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 30 additions and 0 deletions

View File

@ -55,6 +55,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @private this is only public for php 5.3 support in closures
*/
public $lastCacheWrites = array();
private $additionalCleanupPaths = array();
/**
* Constructor.
@ -258,6 +259,12 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$path,
);
if (isset($this->additionalCleanupPaths[$package->getName()])) {
foreach ($this->additionalCleanupPaths[$package->getName()] as $path) {
$this->filesystem->remove($path);
}
}
foreach ($dirsToCleanUp as $dir) {
if (is_dir($dir) && $this->filesystem->isDirEmpty($dir)) {
$this->filesystem->removeDirectory($dir);
@ -291,6 +298,29 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
}
}
/**
* TODO mark private in v3
* @protected This is public due to PHP 5.3
*/
public function addCleanupPath(PackageInterface $package, $path)
{
$this->additionalCleanupPaths[$package->getName()][] = $path;
}
/**
* TODO mark private in v3
* @protected This is public due to PHP 5.3
*/
public function removeCleanupPath(PackageInterface $package, $path)
{
if (isset($this->additionalCleanupPaths[$package->getName()])) {
$idx = array_search($path, $this->additionalCleanupPaths[$package->getName()]);
if (false !== $idx) {
unset($this->additionalCleanupPaths[$package->getName()][$idx]);
}
}
}
/**
* {@inheritDoc}
*/