Skip to content

Commit 58c677e

Browse files
committed
Skip expired Phars in the offline fallback
The fallback listed the cache directory itself and then asked the cache for the newest entry; an expired one made has() return false, which became the Composer binary. Ask the cache about each candidate, newest first, and download when none is usable.
1 parent 91a3184 commit 58c677e

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎src/WP_CLI/Package/ComposerPhar.php‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ public function locate( $quiet = false ) {
4646
}
4747
if ( null === $version ) {
4848
// Offline or getcomposer.org unreachable: reuse the newest Composer already in the cache.
49-
$cached = self::cached_versions( $cache );
50-
if ( $cached ) {
51-
$this->path = $cache->has( "composer/composer-{$cached[0]}.phar" );
52-
WP_CLI::debug( "Using cached Composer {$cached[0]}; version list unavailable.", 'packages' );
53-
return $this->path;
49+
foreach ( self::cached_versions( $cache ) as $cached ) {
50+
$path = $cache->has( "composer/composer-{$cached}.phar" ); // False once the cache's expiry has passed.
51+
if ( $path ) {
52+
$this->path = $path;
53+
WP_CLI::debug( "Using cached Composer {$cached}; version list unavailable.", 'packages' );
54+
return $path;
55+
}
5456
}
5557
$version = 'latest-stable';
5658
}

0 commit comments

Comments
 (0)