diff --git a/src/Action/Symlink.php b/src/Action/Symlink.php index cc36a32..7917797 100644 --- a/src/Action/Symlink.php +++ b/src/Action/Symlink.php @@ -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;