Skip to content

Commit

Permalink
Detect situation where empty repo zip uploaded
Browse files Browse the repository at this point in the history
If FinishReset gets an upload of an *empty* Mercurial repo, then
WaitForRepoEmptyState could wait forever. To catch that situation 99% of
the time, we can simply check for the existence of `00changelog.i` in
the Mercurial repo store: that file is guaranteed to exist if the repo
has commits, so its absence means an empty repo.

To ensure belt-and-suspenders, we still need to implement a timeout in
the WaitForRepoEmptyState method, but this is a good start.
  • Loading branch information
rmunn committed May 28, 2024
1 parent c5feebe commit 2fb2ad4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions backend/LexBoxApi/Services/HgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ await Task.Run(() =>
});
// TODO 789: In theory this shouldn't need an invalidate call? Try with and without
await InvalidateDirCache(code);
// await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows
await WaitForRepoEmptyState(code, RepoEmptyState.Empty);
}

Expand Down Expand Up @@ -110,8 +109,7 @@ public async Task ResetRepo(string code)
await SoftDeleteRepo(code, $"{FileUtils.ToTimestamp(DateTimeOffset.UtcNow)}__reset");
//we must init the repo as uploading a zip is optional
tmpRepo.MoveTo(PrefixRepoFilePath(code));
// await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows
await InvalidateDirCache(code); // TODO 789: Does this work now?
await InvalidateDirCache(code);
await WaitForRepoEmptyState(code, RepoEmptyState.Empty);
}

Expand Down Expand Up @@ -147,8 +145,10 @@ await Task.Run(() =>
await DeleteRepo(code);
tempRepo.MoveTo(PrefixRepoFilePath(code));
await InvalidateDirCache(code);
// await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows
await WaitForRepoEmptyState(code, RepoEmptyState.NonEmpty); // TODO: Either catch the case where someone uploaded a .zip of an empty .hg repo, or set a timeout in WaitForRepoEmptyState
// If someone uploaded an *empty* repo, we don't want to wait forever for a non-empty state
var changelogPath = Path.Join(PrefixRepoFilePath(code), ".hg", "store", "00changelog.i");
var expectedState = File.Exists(changelogPath) ? RepoEmptyState.NonEmpty : RepoEmptyState.Empty;

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
await WaitForRepoEmptyState(code, expectedState);
}

/// <summary>
Expand Down

0 comments on commit 2fb2ad4

Please sign in to comment.