From b5529338661e47ee5c2362beefd42cede82bc6ed Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 24 Jun 2025 12:38:24 +0200 Subject: [PATCH] Move config name to const and change nostow to stowignore --- php/{.nostow => .stowignore} | 0 php/bin/stow | 2 +- php/includes/stow.php | 12 ++++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) rename php/{.nostow => .stowignore} (100%) diff --git a/php/.nostow b/php/.stowignore similarity index 100% rename from php/.nostow rename to php/.stowignore diff --git a/php/bin/stow b/php/bin/stow index 78af282..86fe351 100755 --- a/php/bin/stow +++ b/php/bin/stow @@ -24,7 +24,7 @@ $unwrap = $parsed->get('w'); $stowName = $parsed->get('stow-directory'); $stowPath = path($cwd, $stowName); -$config = new config($stowPath); +$config = new config($stowPath, stow::CONFIG_FILE_NAME); $targetPath = $config->get('targetPath', dirname($stowPath, 2)); if (!is_dir($stowPath)) { diff --git a/php/includes/stow.php b/php/includes/stow.php index 06f68d0..32d6b60 100644 --- a/php/includes/stow.php +++ b/php/includes/stow.php @@ -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);