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

[xaprepare] Improve dotnet-install script logging #8312

Merged
merged 1 commit into from
Aug 30, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,41 +78,34 @@ async Task<bool> DownloadDotNetInstallScript (Context context, string dotnetScri

(bool success, ulong size, HttpStatusCode status) = await Utilities.GetDownloadSizeWithStatus (dotnetScriptUrl);
if (!success) {
string message;
if (status == HttpStatusCode.NotFound) {
message = $"dotnet-install URL '{dotnetScriptUrl}' not found.";
Log.WarningLine ($"dotnet-install URL '{dotnetScriptUrl}' not found.");
} else {
message = $"Failed to obtain dotnet-install script size from URL '{dotnetScriptUrl}'. HTTP status code: {status} ({(int)status})";
Log.WarningLine ($"Failed to obtain dotnet-install script size from URL '{dotnetScriptUrl}'. HTTP status code: {status} ({(int) status})");
}

if (ReportAndCheckCached (message, quietOnError: true))
if (File.Exists (dotnetScriptPath)) {
Log.WarningLine ($"Using cached installation script found in '{dotnetScriptPath}'");
return true;
}
}

DownloadStatus downloadStatus = Utilities.SetupDownloadStatus (context, size, context.InteractiveSession);
Log.StatusLine ($" {context.Characters.Link} {dotnetScriptUrl}", ConsoleColor.White);
await Download (context, dotnetScriptUrl, tempDotnetScriptPath, "dotnet-install", Path.GetFileName (dotnetScriptUrl.LocalPath), downloadStatus);

if (!File.Exists (tempDotnetScriptPath)) {
return ReportAndCheckCached ($"Download of dotnet-install from {dotnetScriptUrl} failed");
if (File.Exists (tempDotnetScriptPath)) {
Utilities.CopyFile (tempDotnetScriptPath, dotnetScriptPath);
Utilities.DeleteFile (tempDotnetScriptPath);
return true;
}

Utilities.CopyFile (tempDotnetScriptPath, dotnetScriptPath);
Utilities.DeleteFile (tempDotnetScriptPath);
return true;

bool ReportAndCheckCached (string message, bool quietOnError = false)
{
if (File.Exists (dotnetScriptPath)) {
Log.WarningLine (message);
Log.WarningLine ($"Using cached installation script found in {dotnetScriptPath}");
return true;
}

if (!quietOnError) {
Log.ErrorLine (message);
Log.ErrorLine ($"Cached installation script not found in {dotnetScriptPath}");
}
if (File.Exists (dotnetScriptPath)) {
Log.WarningLine ($"Download of dotnet-install from '{dotnetScriptUrl}' failed");
Log.WarningLine ($"Using cached installation script found in '{dotnetScriptPath}'");
return true;
} else {
Log.ErrorLine ($"Download of dotnet-install from '{dotnetScriptUrl}' failed");
return false;
}
}
Expand Down Expand Up @@ -193,7 +186,6 @@ async Task<bool> InstallDotNetAsync (Context context, string dotnetPath, string
string scriptFileName = Path.GetFileName (dotnetScriptUrl.LocalPath);
string cachedDotnetScriptPath = Path.Combine (cacheDir, scriptFileName);
if (!await DownloadDotNetInstallScript (context, cachedDotnetScriptPath, dotnetScriptUrl)) {
Log.ErrorLine ($"Failed to download dotnet-install script.");
return false;
}

Expand Down
Loading