mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Attempt to debug improper package extractions
/shrug
This commit is contained in:
parent
f5da33e929
commit
199842547c
@ -1359,8 +1359,6 @@ namespace Bloxstrap
|
|||||||
UpdateProgressBar();
|
UpdateProgressBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
fileStream.Seek(0, SeekOrigin.Begin);
|
|
||||||
|
|
||||||
if (MD5Hash.FromStream(fileStream) != package.Signature)
|
if (MD5Hash.FromStream(fileStream) != package.Signature)
|
||||||
throw new Exception("Signature does not match!");
|
throw new Exception("Signature does not match!");
|
||||||
|
|
||||||
@ -1427,17 +1425,36 @@ namespace Bloxstrap
|
|||||||
if (directory is not null)
|
if (directory is not null)
|
||||||
Directory.CreateDirectory(directory);
|
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))
|
if (File.Exists(extractPath))
|
||||||
{
|
{
|
||||||
var fileManifest = _versionFileManifest.FirstOrDefault(x => x.Name == Path.Combine(PackageDirectories[package.Name], entry.FullName));
|
if (signature is not null && MD5Hash.FromFile(extractPath) == signature)
|
||||||
|
|
||||||
if (fileManifest is not null && MD5Hash.FromFile(extractPath) == fileManifest.Signature)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
File.Delete(extractPath);
|
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}");
|
App.Logger.WriteLine(LOG_IDENT, $"Finished extracting {package.Name}");
|
||||||
|
16
Bloxstrap/Exceptions/AssertionException.cs
Normal file
16
Bloxstrap/Exceptions/AssertionException.cs
Normal 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.")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,8 @@ namespace Bloxstrap.Utility
|
|||||||
|
|
||||||
public static string FromStream(Stream stream)
|
public static string FromStream(Stream stream)
|
||||||
{
|
{
|
||||||
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
using MD5 md5 = MD5.Create();
|
using MD5 md5 = MD5.Create();
|
||||||
return Stringify(md5.ComputeHash(stream));
|
return Stringify(md5.ComputeHash(stream));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user