mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
update custom sources too
This commit is contained in:
parent
134efa17ab
commit
ec3be16aaf
@ -527,7 +527,7 @@ class DownloadCommand extends BaseCommand
|
|||||||
return static::SUCCESS;
|
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');
|
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\store\source');
|
||||||
foreach ($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
@ -537,21 +537,15 @@ class DownloadCommand extends BaseCommand
|
|||||||
if (is_a($class, CustomSourceBase::class, true) && $matches) {
|
if (is_a($class, CustomSourceBase::class, true) && $matches) {
|
||||||
try {
|
try {
|
||||||
$config['source_name'] = $name;
|
$config['source_name'] = $name;
|
||||||
$updated = (new $class())->update($lock, $config);
|
return (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;
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
logger()->warning("[{$current}/{$total}] Failed to check '{$name}': {$e->getMessage()}");
|
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");
|
logger()->debug("[{$current}/{$total}] Custom source handler for '{$name}' not found");
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -570,13 +564,12 @@ class DownloadCommand extends BaseCommand
|
|||||||
$locked_filename = $lock['filename'] ?? '';
|
$locked_filename = $lock['filename'] ?? '';
|
||||||
|
|
||||||
// Skip local types that don't support version detection
|
// 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");
|
logger()->debug("[{$current}/{$total}] Source '{$name}' (type: {$type}) doesn't support version detection, skipping");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get latest version info
|
|
||||||
$latest_info = match ($type) {
|
$latest_info = match ($type) {
|
||||||
'ghtar' => Downloader::getLatestGithubTarball($name, $config),
|
'ghtar' => Downloader::getLatestGithubTarball($name, $config),
|
||||||
'ghtagtar' => Downloader::getLatestGithubTarball($name, $config, 'tags'),
|
'ghtagtar' => Downloader::getLatestGithubTarball($name, $config, 'tags'),
|
||||||
@ -670,7 +663,7 @@ class DownloadCommand extends BaseCommand
|
|||||||
{
|
{
|
||||||
logger()->info("[{$current}/{$total}] Downloading '{$name}'...");
|
logger()->info("[{$current}/{$total}] Downloading '{$name}'...");
|
||||||
|
|
||||||
// Remove old lock entry (this triggers cleanup of old files)
|
// Remove old lock entry
|
||||||
LockFile::put($name, null);
|
LockFile::put($name, null);
|
||||||
|
|
||||||
// Download new version
|
// Download new version
|
||||||
|
|||||||
@ -280,7 +280,7 @@ class Downloader
|
|||||||
if ($download_as === SPC_DOWNLOAD_PRE_BUILT) {
|
if ($download_as === SPC_DOWNLOAD_PRE_BUILT) {
|
||||||
$name = self::getPreBuiltLockName($name);
|
$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
|
// Lock
|
||||||
logger()->debug("Locking git source {$name}");
|
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, [
|
LockFile::lockSource($name, [
|
||||||
'source_type' => SPC_SOURCE_LOCAL,
|
'source_type' => SPC_SOURCE_LOCAL,
|
||||||
'dirname' => $conf['dirname'],
|
'dirname' => $conf['dirname'],
|
||||||
|
'path' => $conf['path'] ?? null,
|
||||||
'move_path' => $conf['path'] ?? $conf['extract'] ?? null,
|
'move_path' => $conf['path'] ?? $conf['extract'] ?? null,
|
||||||
'lock_as' => $download_as,
|
'lock_as' => $download_as,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -155,6 +155,7 @@ class LockFile
|
|||||||
* @param string $name Source name
|
* @param string $name Source name
|
||||||
* @param array{
|
* @param array{
|
||||||
* source_type: string,
|
* source_type: string,
|
||||||
|
* url: ?string,
|
||||||
* dirname?: ?string,
|
* dirname?: ?string,
|
||||||
* filename?: ?string,
|
* filename?: ?string,
|
||||||
* move_path: ?string,
|
* move_path: ?string,
|
||||||
|
|||||||
@ -31,7 +31,7 @@ abstract class CustomSourceBase
|
|||||||
*
|
*
|
||||||
* @param array $lock Lock file entry
|
* @param array $lock Lock file entry
|
||||||
* @param array $config Optional configuration array
|
* @param array $config Optional configuration array
|
||||||
* @return bool True if updated, false otherwise
|
* @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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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';
|
$source_name = $config['source_name'] ?? 'php-src';
|
||||||
|
|
||||||
@ -42,19 +42,14 @@ class PhpSource extends CustomSourceBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($major === 'git') {
|
if ($major === 'git') {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$latest_php = $this->getLatestPHPInfo($major);
|
$latest_php = $this->getLatestPHPInfo($major);
|
||||||
$latest_url = $latest_php['url'];
|
$latest_url = $latest_php['url'];
|
||||||
$locked_url = $lock['url'] ?? '';
|
$filename = basename($latest_url);
|
||||||
|
|
||||||
if ($locked_url !== $latest_url) {
|
return [$latest_url, $filename];
|
||||||
Downloader::downloadSource($source_name, $latest_php, true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -15,14 +15,11 @@ class PostgreSQLSource extends CustomSourceBase
|
|||||||
Downloader::downloadSource('postgresql', self::getLatestInfo(), $force);
|
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();
|
$latest = $this->getLatestInfo();
|
||||||
if (($lock['url'] ?? '') !== $latest['url']) {
|
$filename = basename($latest['url']);
|
||||||
Downloader::downloadSource('postgresql', $latest, true);
|
return [$latest['url'], $filename];
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLatestInfo(): array
|
public function getLatestInfo(): array
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user