Attempt to debug improper package extractions

/shrug
This commit is contained in:
pizzaboxer 2023-08-26 16:21:59 +01:00
parent f5da33e929
commit 199842547c
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
3 changed files with 42 additions and 7 deletions

View File

@ -1359,8 +1359,6 @@ namespace Bloxstrap
UpdateProgressBar();
}
fileStream.Seek(0, SeekOrigin.Begin);
if (MD5Hash.FromStream(fileStream) != package.Signature)
throw new Exception("Signature does not match!");
@ -1427,17 +1425,36 @@ namespace Bloxstrap
if (directory is not null)
Directory.CreateDirectory(directory);
var fileManifest = _versionFileManifest.FirstOrDefault(x => x.Name == Path.Combine(PackageDirectories[package.Name], entry.FullName));
string? signature = fileManifest?.Signature;
if (File.Exists(extractPath))
{
var fileManifest = _versionFileManifest.FirstOrDefault(x => x.Name == Path.Combine(PackageDirectories[package.Name], entry.FullName));
if (fileManifest is not null && MD5Hash.FromFile(extractPath) == fileManifest.Signature)
if (signature is not null && MD5Hash.FromFile(extractPath) == signature)
continue;
File.Delete(extractPath);
}
entry.ExtractToFile(extractPath, true);
bool retry = false;
do
{
using var entryStream = entry.Open();
using var fileStream = new FileStream(extractPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, bufferSize: 0x1000);
await entryStream.CopyToAsync(fileStream);
if (signature is not null && MD5Hash.FromStream(fileStream) != signature)
{
if (retry)
throw new AssertionException($"Checksum of {entry.FullName} post-extraction did not match manifest");
retry = true;
}
}
while (retry);
File.SetLastWriteTime(extractPath, entry.LastWriteTime.DateTime);
}
App.Logger.WriteLine(LOG_IDENT, $"Finished extracting {package.Name}");

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bloxstrap.Exceptions
{
internal class AssertionException : Exception
{
public AssertionException(string message)
: base($"{message}\n\nThis is very likely just an off-chance error. Please report this first, and then start {App.ProjectName} again.")
{
}
}
}

View File

@ -12,6 +12,8 @@ namespace Bloxstrap.Utility
public static string FromStream(Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
using MD5 md5 = MD5.Create();
return Stringify(md5.ComputeHash(stream));
}