From a481dfce3fc5312a2bee581d4df7f72ced52e84b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 13 Jul 2022 10:35:32 +0200 Subject: [PATCH] Fix disk_free_space being called even when not available, fixes #10936 --- src/Composer/Cache.php | 4 ++-- src/Composer/Command/DiagnoseCommand.php | 4 ++++ src/Composer/Console/Application.php | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Composer/Cache.php b/src/Composer/Cache.php index 61ae44f82..cafad5a28 100644 --- a/src/Composer/Cache.php +++ b/src/Composer/Cache.php @@ -162,11 +162,11 @@ class Cache unlink($tempFileName); $message = sprintf( - 'Writing %1$s into cache failed after %2$u of %3$u bytes written, only %4$u bytes of free space available', + 'Writing %1$s into cache failed after %2$u of %3$u bytes written, only %4$s bytes of free space available', $tempFileName, $m[1], $m[2], - @disk_free_space(dirname($tempFileName)) + function_exists('disk_free_space') ? @disk_free_space(dirname($tempFileName)) : 'unknown' ); $this->io->writeError($message); diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index 242c58154..6e56f3a4f 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -370,6 +370,10 @@ EOT */ private function checkDiskSpace(Config $config) { + if (!function_exists('disk_free_space')) { + return true; + } + $minSpaceFree = 1024 * 1024; if ((($df = @disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree) || (($df = @disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index e7c3a32a5..86e89e88b 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -386,7 +386,7 @@ class Application extends BaseApplication Silencer::suppress(); try { $composer = $this->getComposer(false, true); - if ($composer) { + if (null !== $composer && function_exists('disk_free_space')) { $config = $composer->getConfig(); $minSpaceFree = 1024 * 1024;