Skip to content

Commit 7d4ba80

Browse files
authored
gen_stub: Fix php-parser package download (#20775)
If the system wgetrc has the `content-disposition = on` option, the file is actually saved as `PHP-Parser-5.0.0.tar.gz`, causing a subsequent failure. Even with `content-disposition = off`, if for any reason the download file already exists and is corrupted, it won't be overwritten, and a new file such as `v5.0.0.tar.gz.1` is saved instead. We solve both problems by enforcing the name of the downloaded file. Also, if for any other reason the unpacking should fail, remove the created directory to allow further attempts.
1 parent 20f9772 commit 7d4ba80

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

build/gen_stub.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5970,9 +5970,10 @@ function installPhpParser(string $version, string $phpParserDir) {
59705970
chdir(__DIR__);
59715971

59725972
$tarName = "v$version.tar.gz";
5973-
passthru("wget https://github.com/nikic/PHP-Parser/archive/$tarName", $exit);
5973+
$downloadUrl = "https://github.com/nikic/PHP-Parser/archive/$tarName";
5974+
passthru("wget -O $tarName $downloadUrl", $exit);
59745975
if ($exit !== 0) {
5975-
passthru("curl -LO https://github.com/nikic/PHP-Parser/archive/$tarName", $exit);
5976+
passthru("curl -LO $downloadUrl", $exit);
59765977
}
59775978
if ($exit !== 0) {
59785979
throw new Exception("Failed to download PHP-Parser tarball");
@@ -5982,6 +5983,7 @@ function installPhpParser(string $version, string $phpParserDir) {
59825983
}
59835984
passthru("tar xvzf $tarName -C PHP-Parser-$version --strip-components 1", $exit);
59845985
if ($exit !== 0) {
5986+
rmdir($phpParserDir);
59855987
throw new Exception("Failed to extract PHP-Parser tarball");
59865988
}
59875989
unlink(__DIR__ . "/$tarName");

0 commit comments

Comments
 (0)