Skip to content

Commit

Permalink
Check for case insensitive license.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
alerickson committed Nov 22, 2024
1 parent 949c26a commit c8bd0ac
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

/// <summary>
Expand Down

0 comments on commit c8bd0ac

Please sign in to comment.