mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #703 from Noggog/missing-delete-awaits
Missing DeleteDirectory awaits
This commit is contained in:
commit
137e9e73d1
@ -86,8 +86,6 @@ namespace Wabbajack.Common
|
|||||||
throw new JsonException("Type deserialized into null");
|
throw new JsonException("Type deserialized into null");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private class HashJsonConverter : JsonConverter<Hash>
|
private class HashJsonConverter : JsonConverter<Hash>
|
||||||
{
|
{
|
||||||
|
@ -177,7 +177,7 @@ namespace Wabbajack.Lib
|
|||||||
});
|
});
|
||||||
|
|
||||||
Status("Unstaging files");
|
Status("Unstaging files");
|
||||||
onFinish();
|
await onFinish();
|
||||||
|
|
||||||
// Now patch all the files from this archive
|
// Now patch all the files from this archive
|
||||||
await grouping.OfType<PatchedFromArchive>()
|
await grouping.OfType<PatchedFromArchive>()
|
||||||
|
@ -450,7 +450,7 @@ namespace Wabbajack.Lib
|
|||||||
private async Task BuildArchivePatches(Hash archiveSha, IEnumerable<PatchedFromArchive> group,
|
private async Task BuildArchivePatches(Hash archiveSha, IEnumerable<PatchedFromArchive> group,
|
||||||
Dictionary<RelativePath, AbsolutePath> absolutePaths)
|
Dictionary<RelativePath, AbsolutePath> absolutePaths)
|
||||||
{
|
{
|
||||||
using var files = await VFS.StageWith(@group.Select(g => VFS.Index.FileForArchiveHashPath(g.ArchiveHashPath)));
|
await using var files = await VFS.StageWith(@group.Select(g => VFS.Index.FileForArchiveHashPath(g.ArchiveHashPath)));
|
||||||
var byPath = files.GroupBy(f => string.Join("|", f.FilesInFullPath.Skip(1).Select(i => i.Name)))
|
var byPath = files.GroupBy(f => string.Join("|", f.FilesInFullPath.Skip(1).Select(i => i.Name)))
|
||||||
.ToDictionary(f => f.Key, f => f.First());
|
.ToDictionary(f => f.Key, f => f.First());
|
||||||
// Now Create the patches
|
// Now Create the patches
|
||||||
|
@ -28,7 +28,7 @@ namespace Wabbajack.Test
|
|||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
utils.Dispose();
|
utils.DisposeAsync().AsTask().Wait();
|
||||||
_unsub.Dispose();
|
_unsub.Dispose();
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ namespace Wabbajack.Test
|
|||||||
{
|
{
|
||||||
Queue.Dispose();
|
Queue.Dispose();
|
||||||
_unsub.Dispose();
|
_unsub.Dispose();
|
||||||
|
utils.DisposeAsync().AsTask().Wait();
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ using Path = Alphaleonis.Win32.Filesystem.Path;
|
|||||||
|
|
||||||
namespace Wabbajack.Test
|
namespace Wabbajack.Test
|
||||||
{
|
{
|
||||||
public class TestUtils : IDisposable
|
public class TestUtils : IAsyncDisposable
|
||||||
{
|
{
|
||||||
private static Random _rng = new Random();
|
private static Random _rng = new Random();
|
||||||
public TestUtils()
|
public TestUtils()
|
||||||
@ -119,13 +119,14 @@ namespace Wabbajack.Test
|
|||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public async ValueTask DisposeAsync()
|
||||||
{
|
{
|
||||||
var exts = new [] {".md", ".exe"};
|
var exts = new[] { ".md", ".exe" };
|
||||||
WorkingDirectory.Combine(ID).DeleteDirectory();
|
await WorkingDirectory.Combine(ID).DeleteDirectory();
|
||||||
Profiles.Do(p =>
|
Profiles.Do(p =>
|
||||||
{
|
{
|
||||||
foreach (var ext in exts) {
|
foreach (var ext in exts)
|
||||||
|
{
|
||||||
var path = Path.Combine(Directory.GetCurrentDirectory(), p + ext);
|
var path = Path.Combine(Directory.GetCurrentDirectory(), p + ext);
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
@ -246,7 +247,5 @@ namespace Wabbajack.Test
|
|||||||
GenerateRandomFileData(fullPath, i);
|
GenerateRandomFileData(fullPath, i);
|
||||||
return fullPath;
|
return fullPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ using Xunit.Abstractions;
|
|||||||
|
|
||||||
namespace Wabbajack.VirtualFileSystem.Test
|
namespace Wabbajack.VirtualFileSystem.Test
|
||||||
{
|
{
|
||||||
public class VFSTests
|
public class VFSTests : IAsyncLifetime
|
||||||
{
|
{
|
||||||
private static readonly AbsolutePath VFS_TEST_DIR = "vfs_test_dir".ToPath().RelativeToEntryPoint();
|
private static readonly AbsolutePath VFS_TEST_DIR = "vfs_test_dir".ToPath().RelativeToEntryPoint();
|
||||||
private static readonly AbsolutePath TEST_ZIP = "test.zip".RelativeTo(VFS_TEST_DIR);
|
private static readonly AbsolutePath TEST_ZIP = "test.zip".RelativeTo(VFS_TEST_DIR);
|
||||||
@ -18,18 +18,26 @@ namespace Wabbajack.VirtualFileSystem.Test
|
|||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
private readonly ITestOutputHelper _helper;
|
private readonly ITestOutputHelper _helper;
|
||||||
private WorkQueue Queue { get; }
|
private WorkQueue Queue { get; } = new WorkQueue();
|
||||||
|
|
||||||
public VFSTests(ITestOutputHelper helper)
|
public VFSTests(ITestOutputHelper helper)
|
||||||
{
|
{
|
||||||
_helper = helper;
|
_helper = helper;
|
||||||
Utils.LogMessages.Subscribe(f => _helper.WriteLine(f.ShortDescription));
|
Utils.LogMessages.Subscribe(f => _helper.WriteLine(f.ShortDescription));
|
||||||
VFS_TEST_DIR.DeleteDirectory();
|
|
||||||
VFS_TEST_DIR.CreateDirectory();
|
|
||||||
Queue = new WorkQueue();
|
|
||||||
context = new Context(Queue);
|
context = new Context(Queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task InitializeAsync()
|
||||||
|
{
|
||||||
|
await VFS_TEST_DIR.DeleteDirectory();
|
||||||
|
VFS_TEST_DIR.CreateDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DisposeAsync()
|
||||||
|
{
|
||||||
|
await VFS_TEST_DIR.DeleteDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task FilesAreIndexed()
|
public async Task FilesAreIndexed()
|
||||||
{
|
{
|
||||||
@ -51,12 +59,11 @@ namespace Wabbajack.VirtualFileSystem.Test
|
|||||||
await context.IntegrateFromFile( "vfs_cache.bin".RelativeTo(VFS_TEST_DIR));
|
await context.IntegrateFromFile( "vfs_cache.bin".RelativeTo(VFS_TEST_DIR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ArchiveContentsAreIndexed()
|
public async Task ArchiveContentsAreIndexed()
|
||||||
{
|
{
|
||||||
await AddFile(ARCHIVE_TEST_TXT, "This is a test");
|
await AddFile(ARCHIVE_TEST_TXT, "This is a test");
|
||||||
ZipUpFolder(ARCHIVE_TEST_TXT.Parent, TEST_ZIP);
|
await ZipUpFolder(ARCHIVE_TEST_TXT.Parent, TEST_ZIP);
|
||||||
await AddTestRoot();
|
await AddTestRoot();
|
||||||
|
|
||||||
var absPath = "test.zip".RelativeTo(VFS_TEST_DIR);
|
var absPath = "test.zip".RelativeTo(VFS_TEST_DIR);
|
||||||
@ -78,7 +85,7 @@ namespace Wabbajack.VirtualFileSystem.Test
|
|||||||
public async Task DuplicateFileHashes()
|
public async Task DuplicateFileHashes()
|
||||||
{
|
{
|
||||||
await AddFile(ARCHIVE_TEST_TXT, "This is a test");
|
await AddFile(ARCHIVE_TEST_TXT, "This is a test");
|
||||||
ZipUpFolder(ARCHIVE_TEST_TXT.Parent, TEST_ZIP);
|
await ZipUpFolder(ARCHIVE_TEST_TXT.Parent, TEST_ZIP);
|
||||||
|
|
||||||
await AddFile(TEST_TXT, "This is a test");
|
await AddFile(TEST_TXT, "This is a test");
|
||||||
await AddTestRoot();
|
await AddTestRoot();
|
||||||
@ -127,7 +134,7 @@ namespace Wabbajack.VirtualFileSystem.Test
|
|||||||
public async Task CanStageSimpleArchives()
|
public async Task CanStageSimpleArchives()
|
||||||
{
|
{
|
||||||
await AddFile(ARCHIVE_TEST_TXT, "This is a test");
|
await AddFile(ARCHIVE_TEST_TXT, "This is a test");
|
||||||
ZipUpFolder(ARCHIVE_TEST_TXT.Parent, TEST_ZIP);
|
await ZipUpFolder(ARCHIVE_TEST_TXT.Parent, TEST_ZIP);
|
||||||
await AddTestRoot();
|
await AddTestRoot();
|
||||||
|
|
||||||
var res = new FullPath(TEST_ZIP, new[] {(RelativePath)"test.txt"});
|
var res = new FullPath(TEST_ZIP, new[] {(RelativePath)"test.txt"});
|
||||||
@ -136,19 +143,19 @@ namespace Wabbajack.VirtualFileSystem.Test
|
|||||||
var cleanup = await context.Stage(new List<VirtualFile> {file});
|
var cleanup = await context.Stage(new List<VirtualFile> {file});
|
||||||
Assert.Equal("This is a test", await file.StagedPath.ReadAllTextAsync());
|
Assert.Equal("This is a test", await file.StagedPath.ReadAllTextAsync());
|
||||||
|
|
||||||
cleanup();
|
await cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanStageNestedArchives()
|
public async Task CanStageNestedArchives()
|
||||||
{
|
{
|
||||||
await AddFile(ARCHIVE_TEST_TXT, "This is a test");
|
await AddFile(ARCHIVE_TEST_TXT, "This is a test");
|
||||||
ZipUpFolder(ARCHIVE_TEST_TXT.Parent, TEST_ZIP);
|
await ZipUpFolder(ARCHIVE_TEST_TXT.Parent, TEST_ZIP);
|
||||||
|
|
||||||
var inner_dir = @"archive\other\dir".RelativeTo(VFS_TEST_DIR);
|
var inner_dir = @"archive\other\dir".RelativeTo(VFS_TEST_DIR);
|
||||||
inner_dir.CreateDirectory();
|
inner_dir.CreateDirectory();
|
||||||
TEST_ZIP.MoveTo( @"archive\other\dir\nested.zip".RelativeTo(VFS_TEST_DIR));
|
TEST_ZIP.MoveTo( @"archive\other\dir\nested.zip".RelativeTo(VFS_TEST_DIR));
|
||||||
ZipUpFolder(ARCHIVE_TEST_TXT.Parent, TEST_ZIP);
|
await ZipUpFolder(ARCHIVE_TEST_TXT.Parent, TEST_ZIP);
|
||||||
|
|
||||||
await AddTestRoot();
|
await AddTestRoot();
|
||||||
|
|
||||||
@ -159,7 +166,7 @@ namespace Wabbajack.VirtualFileSystem.Test
|
|||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
Assert.Equal("This is a test", await file.StagedPath.ReadAllTextAsync());
|
Assert.Equal("This is a test", await file.StagedPath.ReadAllTextAsync());
|
||||||
|
|
||||||
cleanup();
|
await cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task AddFile(AbsolutePath filename, string text)
|
private static async Task AddFile(AbsolutePath filename, string text)
|
||||||
@ -168,10 +175,10 @@ namespace Wabbajack.VirtualFileSystem.Test
|
|||||||
await filename.WriteAllTextAsync(text);
|
await filename.WriteAllTextAsync(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ZipUpFolder(AbsolutePath folder, AbsolutePath output)
|
private static async Task ZipUpFolder(AbsolutePath folder, AbsolutePath output)
|
||||||
{
|
{
|
||||||
ZipFile.CreateFromDirectory((string)folder, (string)output);
|
ZipFile.CreateFromDirectory((string)folder, (string)output);
|
||||||
folder.DeleteDirectory();
|
await folder.DeleteDirectory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ namespace Wabbajack.VirtualFileSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Action> Stage(IEnumerable<VirtualFile> files)
|
public async Task<Func<Task>> Stage(IEnumerable<VirtualFile> files)
|
||||||
{
|
{
|
||||||
var grouped = files.SelectMany(f => f.FilesInFullPath)
|
var grouped = files.SelectMany(f => f.FilesInFullPath)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
@ -215,18 +215,18 @@ namespace Wabbajack.VirtualFileSystem
|
|||||||
file.StagedPath = file.RelativeName.RelativeTo(tmpPath);
|
file.StagedPath = file.RelativeName.RelativeTo(tmpPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return () =>
|
return async () =>
|
||||||
{
|
{
|
||||||
paths.Do(p =>
|
foreach (var p in paths)
|
||||||
{
|
{
|
||||||
p.DeleteDirectory();
|
await p.DeleteDirectory();
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DisposableList<VirtualFile>> StageWith(IEnumerable<VirtualFile> files)
|
public async Task<AsyncDisposableList<VirtualFile>> StageWith(IEnumerable<VirtualFile> files)
|
||||||
{
|
{
|
||||||
return new DisposableList<VirtualFile>(await Stage(files), files);
|
return new AsyncDisposableList<VirtualFile>(await Stage(files), files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ namespace Wabbajack.VirtualFileSystem
|
|||||||
_knownFiles = new List<HashRelativePath>();
|
_knownFiles = new List<HashRelativePath>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,6 +294,21 @@ namespace Wabbajack.VirtualFileSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class AsyncDisposableList<T> : List<T>, IAsyncDisposable
|
||||||
|
{
|
||||||
|
private Func<Task> _unstage;
|
||||||
|
|
||||||
|
public AsyncDisposableList(Func<Task> unstage, IEnumerable<T> files) : base(files)
|
||||||
|
{
|
||||||
|
_unstage = unstage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask DisposeAsync()
|
||||||
|
{
|
||||||
|
await _unstage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class IndexRoot
|
public class IndexRoot
|
||||||
{
|
{
|
||||||
public static IndexRoot Empty = new IndexRoot();
|
public static IndexRoot Empty = new IndexRoot();
|
||||||
|
Loading…
Reference in New Issue
Block a user