[web-downloads] main: Refactor updatePackagesFile function to update all libraries

From: Date: Wed, 19 Nov 2025 01:23:21 +0000
Subject: [web-downloads] main: Refactor updatePackagesFile function to update all libraries
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-33364@lists.php.net to get a copy of this message
Author: Shivam Mathur (shivammathur) Date: 2025-11-19T06:53:11+05:30 Commit: https://github.com/php/web-downloads/commit/dcdb91ae7d6d7b3bb8711b77077935a59296767b Raw diff: https://github.com/php/web-downloads/commit/dcdb91ae7d6d7b3bb8711b77077935a59296767b.diff Refactor updatePackagesFile function to update all libraries Changed paths: M src/Console/Command/WinlibsCommand.php M tests/Console/Command/WinlibsCommandTest.php Diff: diff --git a/src/Console/Command/WinlibsCommand.php b/src/Console/Command/WinlibsCommand.php index 40888d9..80a6cf1 100644 --- a/src/Console/Command/WinlibsCommand.php +++ b/src/Console/Command/WinlibsCommand.php @@ -176,40 +176,16 @@ private function updatePackagesFile(array $files, string $library): void { $baseDirectory = $this->baseDirectory . "/pecl/deps"; $packagesFile = $baseDirectory . "/packages.txt"; - $syncFile = $packagesFile . '.sync'; if (!is_dir($baseDirectory)) { mkdir($baseDirectory, 0755, true); } - $file_lines = []; - if (file_exists($packagesFile)) { - $file_lines = file($packagesFile, FILE_IGNORE_NEW_LINES); - } + $artifacts = glob($baseDirectory . '/*.zip'); + sort($artifacts); - if(!file_exists($syncFile)) { - $file_lines = array_map(function($file) { - return basename($file); - }, glob($baseDirectory . '/*.zip')); - } else { - foreach ($files as $file) { - $fileName = str_replace($file['artifact_name'], $library, $file['file_name']); - $found = false; - foreach ($file_lines as $no => $line) { - if (str_starts_with($line, $library)) { - $file_lines[$no] = $fileName; - $found = true; - } - } - if (!$found) { - $file_lines[] = $fileName; - } - } - } - sort($file_lines); - file_put_contents($packagesFile, implode("\n", $file_lines)); - if(!file_exists($syncFile)) { - touch($syncFile); - } + $fileLines = array_map('basename', $artifacts); + + file_put_contents($packagesFile, implode("\n", $fileLines)); } } \ No newline at end of file diff --git a/tests/Console/Command/WinlibsCommandTest.php b/tests/Console/Command/WinlibsCommandTest.php index db1847b..41837d4 100644 --- a/tests/Console/Command/WinlibsCommandTest.php +++ b/tests/Console/Command/WinlibsCommandTest.php @@ -189,10 +189,10 @@ public function testPackagesFileIsGeneratedWithoutSyncFile(): void $this->assertEquals(0, $result, 'Command should return success.'); $packagesFile = $this->baseDirectory . '/pecl/deps/packages.txt'; - $syncFile = $packagesFile . '.sync'; $this->assertFileExists($packagesFile); - $this->assertFileExists($syncFile); + $this->assertFileDoesNotExist($packagesFile . '.sync'); + $this->assertSame( ['phpredis-5.3.7-vs16-x64.zip'], file($packagesFile, FILE_IGNORE_NEW_LINES) @@ -223,6 +223,7 @@ public function testPackagesFileUpdatesExistingEntriesAndMaintainsSorting(): voi $this->assertSame( [ 'imagick-3.7.0-vs16-x64.zip', + 'phpredis-5.3.7-vs16-x64.zip', 'phpredis-5.3.8-vs16-x64.zip', ], file($packagesFile, FILE_IGNORE_NEW_LINES)

« previous php.webmaster (#33364) next »