Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for case insensitive license.txt #1758

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading