From 8a8efa4fe5118e9e05c9deaef5453903a0b1e9e1 Mon Sep 17 00:00:00 2001 From: Netkas Date: Sun, 29 Jan 2023 19:19:48 -0500 Subject: [PATCH] Added patch for Non-Tty clients --- src/installer/installer | 23 ++++++++++++++++++-- src/ncc/Managers/ExecutionPointerManager.php | 7 ++++++ src/ncc/Utilities/Functions.php | 17 +++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/installer/installer b/src/installer/installer index 9996434..81d8200 100644 --- a/src/installer/installer +++ b/src/installer/installer @@ -502,11 +502,30 @@ '--filename=composer.phar' ])); $Process->setWorkingDirectory($NCC_INSTALL_PATH); - $Process->setTty(true); + $Process->setTty(Functions::isTtyMode()); try { - $Process->mustRun(); + if($Process->isTty()) + { + $Process->run(); + } + else + { + Console::outWarning('Composer is running in non-interactive mode, this may cause issues'); + + $Process->run(function ($type, $buffer) + { + if (Process::ERR === $type) + { + Console::outError($buffer); + } + else + { + Console::out($buffer); + } + }); + } } catch(ProcessFailedException $e) { diff --git a/src/ncc/Managers/ExecutionPointerManager.php b/src/ncc/Managers/ExecutionPointerManager.php index 9bedc3b..f7fac47 100644 --- a/src/ncc/Managers/ExecutionPointerManager.php +++ b/src/ncc/Managers/ExecutionPointerManager.php @@ -48,6 +48,7 @@ use ncc\ThirdParty\Symfony\Filesystem\Filesystem; use ncc\ThirdParty\Symfony\Process\Process; use ncc\Utilities\Console; + use ncc\Utilities\Functions; use ncc\Utilities\IO; use ncc\Utilities\PathFinder; use ncc\Utilities\Resolver; @@ -409,6 +410,12 @@ $process->enableOutput(); } + if($process->isTty() && !Functions::isTtyMode()) + { + Console::outWarning('The process is configured to use a TTY, but the current environment does not support it'); + $process->setTty(false); + } + Console::outDebug(sprintf('working_directory=%s', $process->getWorkingDirectory())); Console::outDebug(sprintf('timeout=%s', ($process->getTimeout() ?? 0))); Console::outDebug(sprintf('silent=%s', ($unit->ExecutionPolicy->Execute->Silent ? 'true' : 'false'))); diff --git a/src/ncc/Utilities/Functions.php b/src/ncc/Utilities/Functions.php index 863520b..0168bf9 100644 --- a/src/ncc/Utilities/Functions.php +++ b/src/ncc/Utilities/Functions.php @@ -989,4 +989,21 @@ namespace ncc\Utilities; } } + + /** + * Determines if the current process is running in TTY mode + * + * @return bool + */ + public static function isTtyMode(): bool + { + if(!is_null(RuntimeCache::get('posix_isatty'))) + return RuntimeCache::get('posix_isatty'); + + if(function_exists('posix_isatty') === false) + return false; + + RuntimeCache::set('posix_isatty', posix_isatty(STDOUT)); + return (bool)RuntimeCache::get('posix_isatty'); + } } \ No newline at end of file