diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index 57e83cd0..d5054aa9 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -12,6 +12,7 @@ use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\Config; use SPC\store\Downloader; +use SPC\store\LockFile; use SPC\util\DependencyUtil; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; @@ -301,7 +302,7 @@ class DownloadCommand extends BaseCommand throw new WrongUsageException('Windows currently does not support --from-zip !'); } - if (!file_exists(DOWNLOAD_PATH . '/.lock.json')) { + if (!file_exists(LockFile::LOCK_FILE)) { throw new RuntimeException('.lock.json not exist in "downloads/"'); } } catch (RuntimeException $e) { diff --git a/src/SPC/store/LockFile.php b/src/SPC/store/LockFile.php index 45e3a94c..044b2472 100644 --- a/src/SPC/store/LockFile.php +++ b/src/SPC/store/LockFile.php @@ -10,7 +10,7 @@ use SPC\exception\WrongUsageException; class LockFile { - private const string LOCK_FILE = DOWNLOAD_PATH . '/.lock.json'; + public const string LOCK_FILE = DOWNLOAD_PATH . '/.lock.json'; private static ?array $lock_file_content = null; diff --git a/src/SPC/store/pkg/GoModFrankenphp.php b/src/SPC/store/pkg/GoModFrankenphp.php index 59507b6c..31195cd9 100644 --- a/src/SPC/store/pkg/GoModFrankenphp.php +++ b/src/SPC/store/pkg/GoModFrankenphp.php @@ -6,6 +6,7 @@ namespace SPC\store\pkg; use SPC\store\Downloader; use SPC\store\FileSystem; +use SPC\store\LockFile; class GoModFrankenphp extends CustomPackage { @@ -42,7 +43,7 @@ class GoModFrankenphp extends CustomPackage public function extract(string $name): void { $pkgroot = PKG_ROOT_PATH; - $lock = json_decode(FileSystem::readFile(DOWNLOAD_PATH . '/.lock.json'), true); + $lock = json_decode(FileSystem::readFile(LockFile::LOCK_FILE), true); $source_type = $lock[$name]['source_type']; $filename = DOWNLOAD_PATH . '/' . ($lock[$name]['filename'] ?? $lock[$name]['dirname']); $extract = $lock[$name]['move_path'] === null ? "{$pkgroot}/{$name}" : $lock[$name]['move_path']; diff --git a/tests/SPC/builder/BuilderTest.php b/tests/SPC/builder/BuilderTest.php index 2bdf1109..b80f4a0d 100644 --- a/tests/SPC/builder/BuilderTest.php +++ b/tests/SPC/builder/BuilderTest.php @@ -13,6 +13,7 @@ use SPC\builder\LibraryBase; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\FileSystem; +use SPC\store\LockFile; use SPC\util\CustomExt; use SPC\util\DependencyUtil; use Symfony\Component\Console\Input\ArgvInput; @@ -117,7 +118,7 @@ class BuilderTest extends TestCase public function testGetPHPVersionFromArchive() { - $lock = file_exists(DOWNLOAD_PATH . '/.lock.json') ? file_get_contents(DOWNLOAD_PATH . '/.lock.json') : false; + $lock = file_exists(LockFile::LOCK_FILE) ? file_get_contents(LockFile::LOCK_FILE) : false; if ($lock === false) { $this->assertFalse($this->builder->getPHPVersionFromArchive()); } else { diff --git a/tests/SPC/store/DownloaderTest.php b/tests/SPC/store/DownloaderTest.php index 43de396a..91865bfb 100644 --- a/tests/SPC/store/DownloaderTest.php +++ b/tests/SPC/store/DownloaderTest.php @@ -59,8 +59,8 @@ class DownloaderTest extends TestCase public function testLockSource() { LockFile::lockSource('fake-file', ['source_type' => SPC_SOURCE_ARCHIVE, 'filename' => 'fake-file-name', 'move_path' => 'fake-path', 'lock_as' => 'fake-lock-as']); - $this->assertFileExists(DOWNLOAD_PATH . '/.lock.json'); - $json = json_decode(file_get_contents(DOWNLOAD_PATH . '/.lock.json'), true); + $this->assertFileExists(LockFile::LOCK_FILE); + $json = json_decode(file_get_contents(LockFile::LOCK_FILE), true); $this->assertIsArray($json); $this->assertArrayHasKey('fake-file', $json); $this->assertArrayHasKey('source_type', $json['fake-file']);