diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index 3abd75ff..17cb7e42 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -527,7 +527,7 @@ class DownloadCommand extends BaseCommand return static::SUCCESS; } - private function checkCustomSourceUpdate(string $name, array $lock, array $config, int $current, int $total): bool + private function checkCustomSourceUpdate(string $name, array $lock, array $config, int $current, int $total): ?array { $classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\store\source'); foreach ($classes as $class) { @@ -537,21 +537,15 @@ class DownloadCommand extends BaseCommand if (is_a($class, CustomSourceBase::class, true) && $matches) { try { $config['source_name'] = $name; - $updated = (new $class())->update($lock, $config); - if ($updated) { - logger()->info("[{$current}/{$total}] Source '{$name}' updated"); - } else { - logger()->info("[{$current}/{$total}] Source '{$name}' is up to date"); - } - return $updated; + return (new $class())->update($lock, $config); } catch (\Throwable $e) { logger()->warning("[{$current}/{$total}] Failed to check '{$name}': {$e->getMessage()}"); - return false; + return null; } } } - logger()->warning("[{$current}/{$total}] Custom source handler for '{$name}' not found"); - return false; + logger()->debug("[{$current}/{$total}] Custom source handler for '{$name}' not found"); + return null; } /** @@ -570,13 +564,12 @@ class DownloadCommand extends BaseCommand $locked_filename = $lock['filename'] ?? ''; // Skip local types that don't support version detection - if (in_array($type, ['url', 'local', 'unknown'])) { + if (in_array($type, ['local', 'unknown'])) { logger()->debug("[{$current}/{$total}] Source '{$name}' (type: {$type}) doesn't support version detection, skipping"); return false; } try { - // Get latest version info $latest_info = match ($type) { 'ghtar' => Downloader::getLatestGithubTarball($name, $config), 'ghtagtar' => Downloader::getLatestGithubTarball($name, $config, 'tags'), @@ -670,7 +663,7 @@ class DownloadCommand extends BaseCommand { logger()->info("[{$current}/{$total}] Downloading '{$name}'..."); - // Remove old lock entry (this triggers cleanup of old files) + // Remove old lock entry LockFile::put($name, null); // Download new version diff --git a/src/SPC/store/Downloader.php b/src/SPC/store/Downloader.php index a85f639f..73e75018 100644 --- a/src/SPC/store/Downloader.php +++ b/src/SPC/store/Downloader.php @@ -280,7 +280,7 @@ class Downloader if ($download_as === SPC_DOWNLOAD_PRE_BUILT) { $name = self::getPreBuiltLockName($name); } - LockFile::lockSource($name, ['source_type' => SPC_SOURCE_ARCHIVE, 'filename' => $filename, 'move_path' => $move_path, 'lock_as' => $download_as]); + LockFile::lockSource($name, ['source_type' => SPC_SOURCE_ARCHIVE, 'url' => $url, 'filename' => $filename, 'move_path' => $move_path, 'lock_as' => $download_as]); } /** @@ -339,7 +339,7 @@ class Downloader } // Lock logger()->debug("Locking git source {$name}"); - LockFile::lockSource($name, ['source_type' => SPC_SOURCE_GIT, 'dirname' => $name, 'move_path' => $move_path, 'lock_as' => $lock_as]); + LockFile::lockSource($name, ['source_type' => SPC_SOURCE_GIT, 'url' => $url, 'rev' => $branch, 'dirname' => $name, 'move_path' => $move_path, 'lock_as' => $lock_as]); /* // 复制目录过去 @@ -700,6 +700,7 @@ class Downloader LockFile::lockSource($name, [ 'source_type' => SPC_SOURCE_LOCAL, 'dirname' => $conf['dirname'], + 'path' => $conf['path'] ?? null, 'move_path' => $conf['path'] ?? $conf['extract'] ?? null, 'lock_as' => $download_as, ]); diff --git a/src/SPC/store/LockFile.php b/src/SPC/store/LockFile.php index 88ecd6cb..eeb853f9 100644 --- a/src/SPC/store/LockFile.php +++ b/src/SPC/store/LockFile.php @@ -155,6 +155,7 @@ class LockFile * @param string $name Source name * @param array{ * source_type: string, + * url: ?string, * dirname?: ?string, * filename?: ?string, * move_path: ?string, diff --git a/src/SPC/store/source/CustomSourceBase.php b/src/SPC/store/source/CustomSourceBase.php index 84705dfb..8158db55 100644 --- a/src/SPC/store/source/CustomSourceBase.php +++ b/src/SPC/store/source/CustomSourceBase.php @@ -29,9 +29,9 @@ abstract class CustomSourceBase /** * Update the source from its repository * - * @param array $lock Lock file entry - * @param array $config Optional configuration array - * @return bool True if updated, false otherwise + * @param array $lock Lock file entry + * @param array $config Optional configuration array + * @return null|array Latest version info [url, filename], or null if no update needed */ - abstract public function update(array $lock, ?array $config = null): bool; + abstract public function update(array $lock, ?array $config = null): ?array; } diff --git a/src/SPC/store/source/PhpSource.php b/src/SPC/store/source/PhpSource.php index bd3297d9..079d5287 100644 --- a/src/SPC/store/source/PhpSource.php +++ b/src/SPC/store/source/PhpSource.php @@ -30,7 +30,7 @@ class PhpSource extends CustomSourceBase } } - public function update(array $lock, ?array $config = null): bool + public function update(array $lock, ?array $config = null): ?array { $source_name = $config['source_name'] ?? 'php-src'; @@ -42,19 +42,14 @@ class PhpSource extends CustomSourceBase } if ($major === 'git') { - return false; + return null; } $latest_php = $this->getLatestPHPInfo($major); $latest_url = $latest_php['url']; - $locked_url = $lock['url'] ?? ''; + $filename = basename($latest_url); - if ($locked_url !== $latest_url) { - Downloader::downloadSource($source_name, $latest_php, true); - return true; - } - - return false; + return [$latest_url, $filename]; } /** diff --git a/src/SPC/store/source/PostgreSQLSource.php b/src/SPC/store/source/PostgreSQLSource.php index e627a00f..32024530 100644 --- a/src/SPC/store/source/PostgreSQLSource.php +++ b/src/SPC/store/source/PostgreSQLSource.php @@ -15,14 +15,11 @@ class PostgreSQLSource extends CustomSourceBase Downloader::downloadSource('postgresql', self::getLatestInfo(), $force); } - public function update(array $lock, ?array $config = null): bool + public function update(array $lock, ?array $config = null): ?array { $latest = $this->getLatestInfo(); - if (($lock['url'] ?? '') !== $latest['url']) { - Downloader::downloadSource('postgresql', $latest, true); - return true; - } - return false; + $filename = basename($latest['url']); + return [$latest['url'], $filename]; } public function getLatestInfo(): array