From c8bd0ac38f89ba28756a2b050f8685c2068f991a Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:29:44 -0800 Subject: [PATCH 1/2] Check for case insensitive license.txt --- src/code/InstallHelper.cs | 41 ++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index 5f4b0773c..ce8c8de42 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -1338,7 +1338,6 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t _cmdletPassedIn.WriteDebug("In InstallHelper::CallAcceptLicense()"); error = null; var requireLicenseAcceptance = false; - var success = true; if (File.Exists(moduleManifest)) { @@ -1366,22 +1365,45 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t if (!_acceptLicense) { var PkgTempInstallPath = Path.Combine(tempInstallPath, p.Name, newVersion); - var LicenseFilePath = Path.Combine(PkgTempInstallPath, "License.txt"); + if (!Directory.Exists(PkgTempInstallPath)) + { + error = new ErrorRecord( + new ArgumentException($"Package '{p.Name}' could not be installed: Temporary installation path does not exist."), + "TempPathNotFound", + ErrorCategory.ObjectNotFound, + _cmdletPassedIn); + ; + + return false; + } + + string[] files = Directory.GetFiles(PkgTempInstallPath); + + bool foundLicense = false; + string LicenseFilePath = string.Empty; + foreach (string file in files) + { + if (string.Equals(Path.GetFileName(file), "License.txt", StringComparison.OrdinalIgnoreCase)) + { + foundLicense = true; + LicenseFilePath = Path.GetFullPath(file); + break; + } + } - if (!File.Exists(LicenseFilePath)) + if (!foundLicense) { error = new ErrorRecord( new ArgumentException($"Package '{p.Name}' could not be installed: License.txt not found. License.txt must be provided when user license acceptance is required."), "LicenseTxtNotFound", ErrorCategory.ObjectNotFound, - _cmdletPassedIn);; - success = false; + _cmdletPassedIn); - return success; + return false; } // Otherwise read LicenseFile - string licenseText = System.IO.File.ReadAllText(LicenseFilePath); + string licenseText = File.ReadAllText(LicenseFilePath); var acceptanceLicenseQuery = $"Do you accept the license terms for module '{p.Name}'?"; var message = licenseText + "\r\n" + acceptanceLicenseQuery; @@ -1404,12 +1426,13 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t "ForceAcceptLicense", ErrorCategory.InvalidArgument, _cmdletPassedIn); - success = false; + + return false; } } } - return success; + return true; } /// From 05a30c1d94ea9cf0aaebe8fb18413e5a1798a768 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:46:38 -0800 Subject: [PATCH 2/2] Remove extra ; --- src/code/InstallHelper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index ce8c8de42..e31c2b86c 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -1372,7 +1372,6 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t "TempPathNotFound", ErrorCategory.ObjectNotFound, _cmdletPassedIn); - ; return false; }