Implement quick version of .nostow file to prevent certain stows

This commit is contained in:
Tim 2025-04-30 00:06:47 +02:00
parent 7ad7c8d220
commit b690b588c5
2 changed files with 20 additions and 2 deletions

4
php/.nostow Normal file
View File

@ -0,0 +1,4 @@
argvParser.php
functions.php
snips.php
api_key

View File

@ -9,12 +9,26 @@ readonly class stow
public function __construct(
private string $action = 'stow',
private bool $backup = false,
private bool $force = false
private bool $force = false,
) {}
private function getNoStow(string $path): array
{
if (file_exists(path($path, '.nostow'))) {
$noStow = file_get_contents(path($path, '.nostow'));
if ($noStow === false) {
return [];
}
return array_values(array_filter(array_map('trim', explode(PHP_EOL, $noStow))));
} else {
return [];
}
}
function run(string $sourcePath, string $targetPath): void
{
$sourceFiles = array_diff(scandir($sourcePath), ['..', '.']);
$noStow = $this->getNoStow($sourcePath);
$sourceFiles = array_diff(scandir($sourcePath), ['..', '.', '.nostow', ...$noStow]);
foreach ($sourceFiles as $sourceFile) {
$targetFile = path($targetPath, $sourceFile);