Skip to content

Commit ec3be16

Browse files
committed
update custom sources too
1 parent 134efa1 commit ec3be16

File tree

6 files changed

+22
-35
lines changed

6 files changed

+22
-35
lines changed

src/SPC/command/DownloadCommand.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ private function handleUpdate(): int
527527
return static::SUCCESS;
528528
}
529529

530-
private function checkCustomSourceUpdate(string $name, array $lock, array $config, int $current, int $total): bool
530+
private function checkCustomSourceUpdate(string $name, array $lock, array $config, int $current, int $total): ?array
531531
{
532532
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\store\source');
533533
foreach ($classes as $class) {
@@ -537,21 +537,15 @@ private function checkCustomSourceUpdate(string $name, array $lock, array $confi
537537
if (is_a($class, CustomSourceBase::class, true) && $matches) {
538538
try {
539539
$config['source_name'] = $name;
540-
$updated = (new $class())->update($lock, $config);
541-
if ($updated) {
542-
logger()->info("[{$current}/{$total}] Source '{$name}' updated");
543-
} else {
544-
logger()->info("[{$current}/{$total}] Source '{$name}' is up to date");
545-
}
546-
return $updated;
540+
return (new $class())->update($lock, $config);
547541
} catch (\Throwable $e) {
548542
logger()->warning("[{$current}/{$total}] Failed to check '{$name}': {$e->getMessage()}");
549-
return false;
543+
return null;
550544
}
551545
}
552546
}
553-
logger()->warning("[{$current}/{$total}] Custom source handler for '{$name}' not found");
554-
return false;
547+
logger()->debug("[{$current}/{$total}] Custom source handler for '{$name}' not found");
548+
return null;
555549
}
556550

557551
/**
@@ -570,13 +564,12 @@ private function checkArchiveSourceUpdate(string $name, array $lock, array $conf
570564
$locked_filename = $lock['filename'] ?? '';
571565

572566
// Skip local types that don't support version detection
573-
if (in_array($type, ['url', 'local', 'unknown'])) {
567+
if (in_array($type, ['local', 'unknown'])) {
574568
logger()->debug("[{$current}/{$total}] Source '{$name}' (type: {$type}) doesn't support version detection, skipping");
575569
return false;
576570
}
577571

578572
try {
579-
// Get latest version info
580573
$latest_info = match ($type) {
581574
'ghtar' => Downloader::getLatestGithubTarball($name, $config),
582575
'ghtagtar' => Downloader::getLatestGithubTarball($name, $config, 'tags'),
@@ -670,7 +663,7 @@ private function downloadSourceForUpdate(string $name, array $config, int $curre
670663
{
671664
logger()->info("[{$current}/{$total}] Downloading '{$name}'...");
672665

673-
// Remove old lock entry (this triggers cleanup of old files)
666+
// Remove old lock entry
674667
LockFile::put($name, null);
675668

676669
// Download new version

src/SPC/store/Downloader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public static function downloadFile(string $name, string $url, string $filename,
280280
if ($download_as === SPC_DOWNLOAD_PRE_BUILT) {
281281
$name = self::getPreBuiltLockName($name);
282282
}
283-
LockFile::lockSource($name, ['source_type' => SPC_SOURCE_ARCHIVE, 'filename' => $filename, 'move_path' => $move_path, 'lock_as' => $download_as]);
283+
LockFile::lockSource($name, ['source_type' => SPC_SOURCE_ARCHIVE, 'url' => $url, 'filename' => $filename, 'move_path' => $move_path, 'lock_as' => $download_as]);
284284
}
285285

286286
/**
@@ -339,7 +339,7 @@ public static function downloadGit(string $name, string $url, string $branch, ?a
339339
}
340340
// Lock
341341
logger()->debug("Locking git source {$name}");
342-
LockFile::lockSource($name, ['source_type' => SPC_SOURCE_GIT, 'dirname' => $name, 'move_path' => $move_path, 'lock_as' => $lock_as]);
342+
LockFile::lockSource($name, ['source_type' => SPC_SOURCE_GIT, 'url' => $url, 'rev' => $branch, 'dirname' => $name, 'move_path' => $move_path, 'lock_as' => $lock_as]);
343343

344344
/*
345345
// 复制目录过去
@@ -700,6 +700,7 @@ private static function downloadByType(string $type, string $name, array $conf,
700700
LockFile::lockSource($name, [
701701
'source_type' => SPC_SOURCE_LOCAL,
702702
'dirname' => $conf['dirname'],
703+
'path' => $conf['path'] ?? null,
703704
'move_path' => $conf['path'] ?? $conf['extract'] ?? null,
704705
'lock_as' => $download_as,
705706
]);

src/SPC/store/LockFile.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public static function putLockSourceHash(array $lock_options, string $destinatio
155155
* @param string $name Source name
156156
* @param array{
157157
* source_type: string,
158+
* url: ?string,
158159
* dirname?: ?string,
159160
* filename?: ?string,
160161
* move_path: ?string,

src/SPC/store/source/CustomSourceBase.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ abstract public function fetch(bool $force = false, ?array $config = null, int $
2929
/**
3030
* Update the source from its repository
3131
*
32-
* @param array $lock Lock file entry
33-
* @param array $config Optional configuration array
34-
* @return bool True if updated, false otherwise
32+
* @param array $lock Lock file entry
33+
* @param array $config Optional configuration array
34+
* @return null|array Latest version info [url, filename], or null if no update needed
3535
*/
36-
abstract public function update(array $lock, ?array $config = null): bool;
36+
abstract public function update(array $lock, ?array $config = null): ?array;
3737
}

src/SPC/store/source/PhpSource.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function fetch(bool $force = false, ?array $config = null, int $lock_as =
3030
}
3131
}
3232

33-
public function update(array $lock, ?array $config = null): bool
33+
public function update(array $lock, ?array $config = null): ?array
3434
{
3535
$source_name = $config['source_name'] ?? 'php-src';
3636

@@ -42,19 +42,14 @@ public function update(array $lock, ?array $config = null): bool
4242
}
4343

4444
if ($major === 'git') {
45-
return false;
45+
return null;
4646
}
4747

4848
$latest_php = $this->getLatestPHPInfo($major);
4949
$latest_url = $latest_php['url'];
50-
$locked_url = $lock['url'] ?? '';
50+
$filename = basename($latest_url);
5151

52-
if ($locked_url !== $latest_url) {
53-
Downloader::downloadSource($source_name, $latest_php, true);
54-
return true;
55-
}
56-
57-
return false;
52+
return [$latest_url, $filename];
5853
}
5954

6055
/**

src/SPC/store/source/PostgreSQLSource.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ public function fetch(bool $force = false, ?array $config = null, int $lock_as =
1515
Downloader::downloadSource('postgresql', self::getLatestInfo(), $force);
1616
}
1717

18-
public function update(array $lock, ?array $config = null): bool
18+
public function update(array $lock, ?array $config = null): ?array
1919
{
2020
$latest = $this->getLatestInfo();
21-
if (($lock['url'] ?? '') !== $latest['url']) {
22-
Downloader::downloadSource('postgresql', $latest, true);
23-
return true;
24-
}
25-
return false;
21+
$filename = basename($latest['url']);
22+
return [$latest['url'], $filename];
2623
}
2724

2825
public function getLatestInfo(): array

0 commit comments

Comments
 (0)