- Added autoclean of dead symlinks
This commit is contained in:
parent
8396dc6d74
commit
e36756b951
|
@ -14,7 +14,7 @@ class Symlink implements InstallActionInterface
|
|||
protected Config $config,
|
||||
) { }
|
||||
|
||||
public function run(bool $dryRun = false) : mixed
|
||||
public function run(bool $dryRun = false, bool $clean = true) : mixed
|
||||
{
|
||||
if (empty($this->config->destination)) {
|
||||
throw new \InvalidArgumentException("A destination must be provided into Config object.");
|
||||
|
@ -24,6 +24,16 @@ class Symlink implements InstallActionInterface
|
|||
$this->mapPackagesLinks($path, $file);
|
||||
}
|
||||
|
||||
if ( $clean ) {
|
||||
foreach(glob($this->config->destination . DIRECTORY_SEPARATOR . "*") as $file) {
|
||||
if ( is_link($file) ) {
|
||||
if (! file_exists(readlink($file)) ) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $dryRun ) {
|
||||
foreach($this->packageLinks as $link => $source) {
|
||||
$destination = $this->config->destination . DIRECTORY_SEPARATOR . $link;
|
||||
|
|
Loading…
Reference in New Issue