Move config name to const and change nostow to stowignore

This commit is contained in:
Tim
2025-06-24 12:38:24 +02:00
parent 96ac0aecbe
commit b552933866
3 changed files with 9 additions and 5 deletions

View File

@ -5,6 +5,10 @@ readonly class stow
public const ACTION_STOW = 'stow';
public const ACTION_UNSTOW = 'unstow';
public const STOW_IGNORE_FILE = '.stowignore';
public const CONFIG_FILE_NAME = 'config.stow.php';
public function __construct(
private string $action = self::ACTION_STOW,
private bool $backup = false,
@ -14,12 +18,12 @@ readonly class stow
private function getNoStow(string $path): array
{
if (file_exists(path($path, '.nostow'))) {
$noStow = file_get_contents(path($path, '.nostow'));
if (file_exists(path($path, self::STOW_IGNORE_FILE))) {
$noStow = file_get_contents(path($path, self::STOW_IGNORE_FILE));
if ($noStow === false) {
return [];
}
return array_values(array_filter(array_map('trim', explode(PHP_EOL, $noStow))));
return array_values(array_filter(array_map(trim(...), explode(PHP_EOL, $noStow))));
} else {
return [];
}
@ -28,7 +32,7 @@ readonly class stow
function run(string $sourcePath, string $targetPath): void
{
$noStow = $this->getNoStow($sourcePath);
$sourceFiles = array_diff(scandir($sourcePath), ['..', '.', 'config.php', '.nostow', ...$noStow]);
$sourceFiles = array_diff(scandir($sourcePath), ['..', '.', self::CONFIG_FILE_NAME, self::STOW_IGNORE_FILE, ...$noStow]);
foreach ($sourceFiles as $sourceFile) {
$targetFile = path($targetPath, $sourceFile);