Delete old mirrored files

This commit is contained in:
Timothy Baldridge 2021-12-19 15:20:24 -07:00
parent a3e545281e
commit 77bd85bb47
3 changed files with 27 additions and 1 deletions

View File

@ -227,6 +227,13 @@ public class ValidateLists : IVerb
}
await ExportReports(reports, validatedLists, token);
var usedMirroredFiles = validatedLists.SelectMany(a => a.Archives)
.Where(m => m.Status == ArchiveStatus.Mirrored)
.Select(m => m.Original.Hash)
.ToHashSet();
await DeleteOldMirrors(mirroredFiles, usedMirroredFiles);
return 0;
}
@ -356,6 +363,16 @@ public class ValidateLists : IVerb
await using var upgradedMetasFile = reports.Combine("upgraded.json")
.Open(FileMode.Create, FileAccess.Write, FileShare.None);
await _dtos.Serialize(upgradedMetas, upgradedMetasFile, true);
}
private async Task DeleteOldMirrors(IEnumerable<Hash> mirroredFiles, IReadOnlySet<Hash> usedMirroredFiles)
{
foreach (var file in mirroredFiles.Where(file => !usedMirroredFiles.Contains(file)))
{
await _wjClient.DeleteMirror(file);
}
}
private async Task<(ArchiveStatus, Archive)> DownloadAndValidate(Archive archive, CancellationToken token)

View File

@ -320,4 +320,13 @@ public class Client
{
return (await _client.GetFromJsonAsync<ValidatedArchive[]>("https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/configs/forced_healing.json", _dtos.Options, token))!;
}
public async Task DeleteMirror(Hash hash)
{
_logger.LogInformation("Deleting mirror of {Hash}", hash);
var msg = await MakeMessage(HttpMethod.Delete, new Uri($"{_configuration.BuildServerUrl}mirrored_files/{hash.ToHex()}"));
var result = await _client.SendAsync(msg);
if (!result.IsSuccessStatusCode)
throw new HttpException(result);
}
}

View File

@ -34,7 +34,7 @@ public class WabbajackApiTokenProvider : ITokenProvider<WabbajackApiState>
return new WabbajackApiState
{
MetricsKey = wjToken,
AuthorKey = AuthorKeyPath.FileExists() ? await AuthorKeyPath.ReadAllTextAsync() : null
AuthorKey = AuthorKeyPath.FileExists() ? (await AuthorKeyPath.ReadAllTextAsync()).Trim() : null
};
}