diff options
author | Xi Ruoyao <xry111@xry111.site> | 2023-07-03 17:22:17 +0800 |
---|---|---|
committer | Xi Ruoyao <xry111@xry111.site> | 2023-07-03 17:22:17 +0800 |
commit | 19ff1dadd1d23a070a547d78f52694bfbb6660aa (patch) | |
tree | 07bd18dec78e8d41040635475b4327d424436f08 /lfs-latest-git.php | |
parent | 48834cf197e62ba7941aeefbcbf58933854e2acf (diff) |
currency: Refactor http_get_file to avoid duplicating preg_match
Check special cases and return early.
Diffstat (limited to 'lfs-latest-git.php')
-rw-r--r-- | lfs-latest-git.php | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/lfs-latest-git.php b/lfs-latest-git.php index 06887b0bd..90a31a928 100644 --- a/lfs-latest-git.php +++ b/lfs-latest-git.php @@ -69,17 +69,7 @@ function find_even_max( $lines, $regex_match, $regex_replace ) function http_get_file( $url ) { - if ( ! preg_match( "/sourceforge/", $url ) && - ! preg_match( "/mpfr/", $url ) && - ! preg_match( "/psmisc/", $url ) ) - { - exec( "curl --location --silent --max-time 30 $url", $dir ); - - $s = implode( "\n", $dir ); - $dir = strip_tags( $s ); - return explode( "\n", $dir ); - } - else if ( preg_match( "/mpfr/", $url ) ) + if ( preg_match( "/mpfr/", $url ) ) { # There seems to be a problem with the mpfs certificate exec( "curl --location --silent --insecure --max-time 30 $url", $dir ); @@ -87,11 +77,19 @@ function http_get_file( $url ) $dir = strip_tags( $s ); return explode( "\n", $dir ); } - else + + if ( preg_match( "/sourceforge/", $url ) || + preg_match( "/psmisc/", $url ) ) { exec( "lynx -dump $url 2>/dev/null", $lines ); return $lines; } + + exec( "curl --location --silent --max-time 30 $url", $dir ); + + $s = implode( "\n", $dir ); + $dir = strip_tags( $s ); + return explode( "\n", $dir ); } function max_parent( $dirpath, $prefix ) |