Author: Shivam Mathur (shivammathur)
Date: 2025-11-20T09:03:41+05:30

Commit: 
https://github.com/php/web-downloads/commit/f764a52931c9abf544f5622f99287b4f7dd32acb
Raw diff: 
https://github.com/php/web-downloads/commit/f764a52931c9abf544f5622f99287b4f7dd32acb.diff

Cleanup zip files on empty ref in SeriesUpdateCommand

Changed paths:
  M  src/Console/Command/SeriesUpdateCommand.php
  M  tests/Console/Command/SeriesUpdateCommandTest.php


Diff:

diff --git a/src/Console/Command/SeriesUpdateCommand.php 
b/src/Console/Command/SeriesUpdateCommand.php
index e72ba8f..3d4ff0a 100644
--- a/src/Console/Command/SeriesUpdateCommand.php
+++ b/src/Console/Command/SeriesUpdateCommand.php
@@ -131,12 +131,34 @@ private function updateSeriesFiles(
                 if (file_exists($filePath)) {
                     unlink($filePath);
                 }
+                if ($package === null) {
+                    $this->deleteLibraryArtifacts($vsVersion, $arch, $library);
+                }
                 continue;
             }
 
             $tmpFile = $filePath . '.tmp';
             file_put_contents($tmpFile, implode("\n", $lines), LOCK_EX);
             rename($tmpFile, $filePath);
+
+            if ($package === null) {
+                $this->deleteLibraryArtifacts($vsVersion, $arch, $library);
+            }
+        }
+    }
+
+    private function deleteLibraryArtifacts(string $vsVersion, string $arch, 
string $library): void
+    {
+        $artifactDir = $this->baseDirectory . '/php-sdk/deps/' . $vsVersion . 
'/' . $arch;
+        if (!is_dir($artifactDir)) {
+            return;
+        }
+
+        $pattern = $artifactDir . '/' . $library . '-*';
+        foreach (glob($pattern) as $file) {
+            if (is_file($file)) {
+                unlink($file);
+            }
         }
     }
 }
\ No newline at end of file
diff --git a/tests/Console/Command/SeriesUpdateCommandTest.php 
b/tests/Console/Command/SeriesUpdateCommandTest.php
index c419fde..011126f 100644
--- a/tests/Console/Command/SeriesUpdateCommandTest.php
+++ b/tests/Console/Command/SeriesUpdateCommandTest.php
@@ -136,6 +136,15 @@ public function testRemovesLibraryWhenNoPackageProvided(): 
void
             'libzip-1.9.1-vs17-x64.zip',
         ]));
 
+        $depsX86 = $this->baseDirectory . '/php-sdk/deps/vs17/x86';
+        $depsX64 = $this->baseDirectory . '/php-sdk/deps/vs17/x64';
+        mkdir($depsX86, 0755, true);
+        mkdir($depsX64, 0755, true);
+        file_put_contents($depsX86 . '/libzip-1.9.1.zip', 'x86 artifact');
+        file_put_contents($depsX64 . '/libzip-1.9.1.zip', 'x64 artifact');
+        file_put_contents($depsX86 . '/curl-7.88.0.zip', 'keep x86');
+        file_put_contents($depsX64 . '/curl-7.88.0.zip', 'keep x64');
+
         $this->createTask([
             'php_version' => '8.1',
             'vs_version' => 'vs17',
@@ -157,6 +166,11 @@ public function testRemovesLibraryWhenNoPackageProvided(): 
void
 
         $x64Lines = file($filePathX64, FILE_IGNORE_NEW_LINES);
         $this->assertSame(['curl-7.88.0-vs17-x64.zip'], $x64Lines);
+
+        $this->assertFileDoesNotExist($depsX86 . '/libzip-1.9.1.zip');
+        $this->assertFileDoesNotExist($depsX64 . '/libzip-1.9.1.zip');
+        $this->assertFileExists($depsX86 . '/curl-7.88.0.zip');
+        $this->assertFileExists($depsX64 . '/curl-7.88.0.zip');
     }
 
     public function testCreatesSeriesFileWhenMissing(): void

Reply via email to