Making installer more robust

This commit is contained in:
Pavel Shevaev 2025-03-03 15:27:43 +03:00
parent 86408821a5
commit 0a5c12e366
2 changed files with 16 additions and 8 deletions

View File

@ -6,8 +6,8 @@ task('dotnet_set_env', ['always' => true], function() {
dotnet_set_env(); dotnet_set_env();
}); });
task('dotnet_install', function() { task('dotnet_install', function(array $args) {
DotnetSupport::install(); DotnetSupport::install(isset($args[0]) && $args[0] === '--force');
}); });
function dotnet_shell($cmd) function dotnet_shell($cmd)

View File

@ -7,13 +7,12 @@ class DotnetSupport
{ {
const VERSION = "8.0.0"; const VERSION = "8.0.0";
static function install() static function install(bool $force = false)
{ {
$version = self::VERSION; $version = self::VERSION;
$has_dotnet = true;
$dotnet_curr_ver = ""; $dotnet_curr_ver = "";
//let's add to PATH
$prev_path = self::addEnvPath(); $prev_path = self::addEnvPath();
try try
{ {
@ -22,17 +21,26 @@ class DotnetSupport
} }
catch(\Throwable $th) catch(\Throwable $th)
{ {
$has_dotnet = false; $force = true;
} }
finally finally
{ {
//let's restore prev PATH
self::setEnvPath($prev_path); self::setEnvPath($prev_path);
} }
if($has_dotnet && version_compare($dotnet_curr_ver, $version) >= 0) if(!$force)
{
$dotnet_ver_items = explode('.', $dotnet_curr_ver);
$target_ver_items = explode('.', $version);
//let's force install if current major version is not equal
$force = isset($dotnet_ver_items[0]) && $dotnet_ver_items[0] !== $target_ver_items[0];
}
if(!$force)
return; return;
print("DOTNET VERSION MISMATCH: $dotnet_curr_ver < $version\n"); print("DOTNET VERSION MISMATCH: $dotnet_curr_ver is not compatible with $version\n");
$install_file_path = self::getInstallerPath(); $install_file_path = self::getInstallerPath();