Fix Wabbajack.Server and Wabbajack.VirtualFileSystem

This commit is contained in:
erri120 2021-01-09 19:53:44 +01:00
parent 9d79aa7381
commit 03a68da0d1
7 changed files with 32 additions and 24 deletions

View File

@ -211,9 +211,9 @@ namespace Wabbajack.BuildServer.Test
ModListData = new ModList();
ModListData.Archives.Add(
new Archive(new HTTPDownloader.State(MakeURL(modFileName.ToString())))
new Archive(new HTTPDownloader.State(MakeURL(modFileName)))
{
Hash = await test_archive_path.FileHashAsync(),
Hash = await test_archive_path.FileHashAsync() ?? Hash.Empty,
Name = "test_archive",
Size = test_archive_path.Size,
});
@ -237,7 +237,7 @@ namespace Wabbajack.BuildServer.Test
Description = "A test",
DownloadMetadata = new DownloadMetadata
{
Hash = await modListPath.FileHashAsync(),
Hash = await modListPath.FileHashAsync() ?? Hash.Empty,
Size = modListPath.Size
},
Links = new ModlistMetadata.LinksObject

View File

@ -26,7 +26,9 @@ namespace Wabbajack.BuildServer.Test
var hash = await tf.Path.FileHashAsync();
await maintainer.Ingest(tf.Path);
Assert.True(maintainer.TryGetPath(hash, out var found));
Assert.NotNull(hash);
Assert.True(maintainer.TryGetPath(hash!.Value, out var found));
Assert.Equal(await tf2.Path.ReadAllBytesAsync(), await found.ReadAllBytesAsync());
}
@ -40,10 +42,12 @@ namespace Wabbajack.BuildServer.Test
await tf.Path.WriteAllBytesAsync(RandomData(1024));
var hash = await tf.Path.FileHashAsync();
await tf.Path.CopyToAsync(Fixture.ServerArchivesFolder.Combine(hash.ToHex()));
Assert.NotNull(hash);
await tf.Path.CopyToAsync(Fixture.ServerArchivesFolder.Combine(hash!.Value.ToHex()));
maintainer.Start();
Assert.True(maintainer.TryGetPath(hash, out var found));
Assert.True(maintainer.TryGetPath(hash!.Value, out var found));
}
}
}

View File

@ -24,9 +24,10 @@ namespace Wabbajack.Server.Test
var file = new TempFile();
await file.Path.WriteAllBytesAsync(RandomData(1024 * 1024 * 6));
var dataHash = await file.Path.FileHashAsync();
Assert.NotNull(dataHash);
await Fixture.GetService<ArchiveMaintainer>().Ingest(file.Path);
Assert.True(Fixture.GetService<ArchiveMaintainer>().HaveArchive(dataHash));
Assert.True(Fixture.GetService<ArchiveMaintainer>().HaveArchive(dataHash!.Value));
var sql = Fixture.GetService<SqlService>();
@ -34,7 +35,7 @@ namespace Wabbajack.Server.Test
{
Created = DateTime.UtcNow,
Rationale = "Test File",
Hash = dataHash
Hash = dataHash!.Value
});
var uploader = Fixture.GetService<MirrorUploader>();
@ -43,7 +44,7 @@ namespace Wabbajack.Server.Test
var archive = new Archive(new HTTPDownloader.State(MakeURL(dataHash.ToString())))
{
Hash = dataHash,
Hash = dataHash!.Value,
Size = file.Path.Size
};

View File

@ -1,4 +1,4 @@
using System;
#nullable enable
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
@ -40,17 +40,19 @@ namespace Wabbajack.BuildServer.Controllers
_logger.Log(LogLevel.Information, $"Found {files.Count} game files");
using var queue = new WorkQueue();
var hashed = await files.PMap(queue, async pair =>
var hashed = (await files.PMap(queue, async pair =>
{
var hash = await pair.File.FileHashCachedAsync();
if (hash == null) return null;
return await _sql.GetOrEnqueueArchive(new Archive(new GameFileSourceDownloader.State
{
Game = pair.Game.Game,
GameFile = pair.File.RelativeTo(pair.Game.GameLocation()),
GameVersion = pair.Game.InstalledVersion,
Hash = hash
}) {Name = pair.File.FileName.ToString(), Size = pair.File.Size, Hash = hash});
});
Hash = hash.Value
}) {Name = pair.File.FileName.ToString(), Size = pair.File.Size, Hash = hash.Value});
})).NotNull();
await _quickSync.Notify<ArchiveDownloader>();
return Ok(hashed);

View File

@ -83,7 +83,7 @@ namespace Wabbajack.Server.Services
var hash = await tempPath.Path.FileHashAsync();
if (nextDownload.Archive.Hash != default && hash != nextDownload.Archive.Hash)
if (hash == null || (nextDownload.Archive.Hash != default && hash != nextDownload.Archive.Hash))
{
_logger.Log(LogLevel.Warning,
$"Downloaded archive hashes don't match for {nextDownload.Archive.State.PrimaryKeyString} {nextDownload.Archive.Hash} {nextDownload.Archive.Size} vs {hash} {tempPath.Path.Size}");
@ -98,7 +98,7 @@ namespace Wabbajack.Server.Services
continue;
}
nextDownload.Archive.Hash = hash;
nextDownload.Archive.Hash = hash.Value;
nextDownload.Archive.Size = tempPath.Path.Size;
_logger.Log(LogLevel.Information, $"Archiving {nextDownload.Archive.State.PrimaryKeyString}");

View File

@ -36,19 +36,20 @@ namespace Wabbajack.Server.Services
return _settings.ArchivePath.Combine(hash.ToHex());
}
public async Task<AbsolutePath> Ingest(AbsolutePath file)
public async Task Ingest(AbsolutePath file)
{
var hash = await file.FileHashAsync();
var path = ArchivePath(hash);
if (HaveArchive(hash))
if (hash == null) return;
var path = ArchivePath(hash.Value);
if (HaveArchive(hash.Value))
{
await file.DeleteAsync();
return path;
return;
}
var newPath = _settings.ArchivePath.Combine(hash.ToHex());
var newPath = _settings.ArchivePath.Combine(hash.Value.ToHex());
await file.MoveToAsync(newPath);
return path;
}
public bool HaveArchive(Hash hash)

View File

@ -190,10 +190,10 @@ namespace Wabbajack.VirtualFileSystem
public static async Task<VirtualFile> Analyze(Context context, VirtualFile parent, IStreamFactory extractedFile,
IPath relPath, int depth = 0)
{
Hash hash = default;
Hash hash;
if (extractedFile is NativeFileStreamFactory)
{
hash = await ((AbsolutePath)extractedFile.Name).FileHashCachedAsync();
hash = await ((AbsolutePath)extractedFile.Name).FileHashCachedAsync() ?? Hash.Empty;
}
else
{