Skip to content

Commit

Permalink
Merge #3860 Include repo etags in transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Jul 21, 2023
2 parents d1dd847 + f51c439 commit 4734804
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
- [Core] Stop trying to check free space on Mono (#3850 by: HebaruSan; reviewed: techman83)
- [Core] Handle missing KSP2 exe (#3854 by: HebaruSan; reviewed: techman83)
- [Core] Linux network fixes (#3859 by: HebaruSan; reviewed: techman83)
- [Core] Include repo etags in transactions (#3860 by: HebaruSan; reviewed: techman83)

### Internal

Expand Down
11 changes: 1 addition & 10 deletions Core/Net/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,7 @@ public static RepoUpdateResult UpdateAllRepositories(RegistryManager registry_ma
.ToArray();

// Loading done, commit etags
foreach (var kvp in savedEtags)
{
var repo = repos.Where(r => r.uri == kvp.Key).FirstOrDefault();
var etag = kvp.Value;
if (repo != null)
{
log.DebugFormat("Setting etag for {0}: {1}", repo.name, etag);
repo.last_server_etag = etag;
}
}
registry_manager.registry.SetETags(savedEtags);

// Clean up temp files
foreach (var f in files)
Expand Down
23 changes: 23 additions & 0 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,29 @@ private void EnlistWithTransaction()

#endregion

/// <summary>
/// Set the etag values of the repositories
/// Provided in the API so it can enlist us in the transaction
/// </summary>
/// <param name="savedEtags">Mapping from repo URLs to etags received from servers</param>
public void SetETags(Dictionary<Uri, string> savedEtags)
{
log.Debug("Setting repo etags");

// Make sure etags get reverted if the transaction fails
EnlistWithTransaction();

foreach (var kvp in savedEtags)
{
var etag = kvp.Value;
foreach (var repo in repositories.Values.Where(r => r.uri == kvp.Key))
{
log.DebugFormat("Setting etag for {0}: {1}", repo.name, etag);
repo.last_server_etag = etag;
}
}
}

public void SetAllAvailable(IEnumerable<CkanModule> newAvail)
{
log.DebugFormat(
Expand Down

0 comments on commit 4734804

Please sign in to comment.