update custom sources too

This commit is contained in:
henderkes 2026-01-01 14:48:21 +01:00
parent 134efa17ab
commit ec3be16aaf
6 changed files with 22 additions and 35 deletions

View File

@ -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

View File

@ -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,
]);

View File

@ -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,

View File

@ -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;
}

View File

@ -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];
}
/**

View File

@ -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