Skip to content

Commit

Permalink
[xaprepare] Improve dotnet-install script logging
Browse files Browse the repository at this point in the history
Context: dotnet#8311 (comment)

Improves the logging around attempts to download or calculate the size
of the dotnet-install script.  Messages about cached install script use
will be more explicit, and readability of failure cases should also be
improved.
  • Loading branch information
pjcollins committed Aug 30, 2023
1 parent 6862b52 commit 060550c
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions build-tools/xaprepare/xaprepare/Steps/Step_InstallDotNetPreview.cs
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

0 comments on commit 060550c

Please sign in to comment.