Skip to content

Commit 5283b05

Browse files
committed
Simplify and harden scenario for file not found locally
Rather than appending the Etag to the download provider only if force!=true, skip adding it too when the local file doesn't exist. It typically means we'll need to fully download and we were checking that separately after checking for not-modified, which duplicated some code. Also check for temp path before enumerating the first .cs, since sometimes the dir might not exist (download failed?) and we would fail with a cryptic IO exception.
1 parent 2cc58f5 commit 5283b05

1 file changed

Lines changed: 14 additions & 23 deletions

File tree

src/Core/RemoteRunner.cs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ public class RemoteRunner(RemoteRef location, string toolName, Config? config =
1111

1212
public async Task<int> RunAsync(string[] args, bool aot, bool force = false)
1313
{
14-
// Only use cached ETag if not forcing a fresh download
15-
if (!force)
14+
var program = Path.Combine(location.TempPath, location.Path ?? "program.cs");
15+
16+
#if DEBUG
17+
AnsiConsole.MarkupLine($"[blue]{location}[/] :backhand_index_pointing_right: [link]{program}[/]");
18+
#endif
19+
20+
// Only use cached ETag if not forcing a fresh download, and file exists locally (otherwise we'll always download)
21+
if (!force && File.Exists(program))
1622
{
1723
var etag = config.GetString(toolName, location.ToString(), "etag");
1824
if (etag != null && Directory.Exists(location.TempPath))
@@ -46,8 +52,6 @@ public async Task<int> RunAsync(string[] args, bool aot, bool force = false)
4652
return 1;
4753
}
4854

49-
var program = Path.Combine(location.TempPath, location.Path ?? "program.cs");
50-
5155
if (contents.StatusCode != HttpStatusCode.NotModified)
5256
{
5357
#if DEBUG
@@ -69,25 +73,6 @@ await AnsiConsole.Status().StartAsync($":open_file_folder: {location} :backhand_
6973

7074
updated = true;
7175
}
72-
else if (!File.Exists(program))
73-
{
74-
// Redownload if etag matches but file was cleared from local cache somehow
75-
contents = await provider.GetAsync(location with { ETag = null });
76-
if (!contents.IsSuccessStatusCode)
77-
{
78-
AnsiConsole.MarkupLine($":cross_mark: Reference [yellow]{location}[/] not found.");
79-
return 1;
80-
}
81-
82-
await contents.ExtractToAsync(location);
83-
84-
if (contents.Headers.ETag?.ToString() is { } newEtag &&
85-
newEtag != config.GetString(toolName, location.ToString(), "etag"))
86-
{
87-
config = config.SetString(toolName, location.ToString(), "etag", newEtag);
88-
updated = true;
89-
}
90-
}
9176

9277
if (!File.Exists(program))
9378
{
@@ -97,6 +82,12 @@ await AnsiConsole.Status().StartAsync($":open_file_folder: {location} :backhand_
9782
return 1;
9883
}
9984

85+
if (!Directory.Exists(location.TempPath))
86+
{
87+
AnsiConsole.MarkupLine($":cross_mark: Failed to download. Please retry or debug with --dnx-debug.");
88+
return 1;
89+
}
90+
10091
var first = Directory.EnumerateFiles(location.TempPath, "*.cs", SearchOption.TopDirectoryOnly).FirstOrDefault();
10192
if (first is null)
10293
{

0 commit comments

Comments
 (0)