- Added autoclean of dead symlinks
This commit is contained in:
1 parent
8396dc6d74
commit
e36756b951
1 file changed
+11
-1
+11
-1
@@ -14,7 +14,7 @@ class Symlink implements InstallActionInterface
|
|||||||
protected Config $config,
|
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)) {
|
if (empty($this->config->destination)) {
|
||||||
throw new \InvalidArgumentException("A destination must be provided into Config object.");
|
throw new \InvalidArgumentException("A destination must be provided into Config object.");
|
||||||
@@ -24,6 +24,16 @@ class Symlink implements InstallActionInterface
|
|||||||
$this->mapPackagesLinks($path, $file);
|
$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 ) {
|
if ( ! $dryRun ) {
|
||||||
foreach($this->packageLinks as $link => $source) {
|
foreach($this->packageLinks as $link => $source) {
|
||||||
$destination = $this->config->destination . DIRECTORY_SEPARATOR . $link;
|
$destination = $this->config->destination . DIRECTORY_SEPARATOR . $link;
|
||||||
|
|||||||
Reference in new issue
Block a user