Stow: allow recursing unstow as well
This commit is contained in:
parent
33ba450383
commit
2d0c74b25e
26
bin/bin/stow
26
bin/bin/stow
@ -64,11 +64,15 @@ readonly class stow
|
||||
foreach ($sourceFiles as $sourceFile) {
|
||||
$targetFile = path($targetPath, $sourceFile);
|
||||
$stowFile = path($sourcePath, $sourceFile);
|
||||
$isStowed = is_link($targetFile) && readlink($targetFile) === $stowFile;
|
||||
|
||||
if ($this->action === 'stow') {
|
||||
if (is_link($targetFile)) {
|
||||
line("File $targetFile is already stowed from $stowFile");
|
||||
$targetLink = readlink($targetFile);
|
||||
if ($targetLink === $stowFile) {
|
||||
line("File $targetFile is already stowed from $stowFile");
|
||||
} else {
|
||||
line("File $targetFile is linked from $targetLink");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (is_dir($targetFile)) {
|
||||
@ -97,14 +101,24 @@ readonly class stow
|
||||
continue;
|
||||
}
|
||||
}
|
||||
line("Stow $stowFile to $targetFile");
|
||||
line("Stow $targetFile from $stowFile");
|
||||
symlink($stowFile, $targetFile);
|
||||
} elseif ($this->action === 'unstow') {
|
||||
if (!$isStowed) {
|
||||
line("File $targetFile is not stowed from $stowFile");
|
||||
if (is_link($targetFile) && readlink($targetFile) === $stowFile) {
|
||||
line("Unstow $targetFile from $stowFile");
|
||||
unlink($targetFile);
|
||||
continue;
|
||||
}
|
||||
unlink($targetFile);
|
||||
if (is_dir($targetFile)) {
|
||||
if (is_dir($stowFile)) {
|
||||
line("File $targetFile and $stowFile are folders, recurse into existing folders");
|
||||
$this->run($stowFile, $targetFile);
|
||||
continue;
|
||||
} else {
|
||||
line("File $targetFile is a folder, but stow file $stowFile is not a folder");
|
||||
}
|
||||
}
|
||||
line("File $targetFile is not stowed from $stowFile");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user