mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Context.Stage's return action swapped to Func<Task>
So that its internal delete directory call can be awaited
This commit is contained in:
parent
f8d692afd0
commit
69f18f2e22
@ -177,7 +177,7 @@ namespace Wabbajack.Lib
|
||||
});
|
||||
|
||||
Status("Unstaging files");
|
||||
onFinish();
|
||||
await onFinish();
|
||||
|
||||
// Now patch all the files from this archive
|
||||
await grouping.OfType<PatchedFromArchive>()
|
||||
|
@ -450,7 +450,7 @@ namespace Wabbajack.Lib
|
||||
private async Task BuildArchivePatches(Hash archiveSha, IEnumerable<PatchedFromArchive> group,
|
||||
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)))
|
||||
.ToDictionary(f => f.Key, f => f.First());
|
||||
// Now Create the patches
|
||||
|
@ -141,7 +141,7 @@ namespace Wabbajack.VirtualFileSystem.Test
|
||||
var cleanup = await context.Stage(new List<VirtualFile> {file});
|
||||
Assert.Equal("This is a test", await file.StagedPath.ReadAllTextAsync());
|
||||
|
||||
cleanup();
|
||||
await cleanup();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -164,7 +164,7 @@ namespace Wabbajack.VirtualFileSystem.Test
|
||||
foreach (var file in files)
|
||||
Assert.Equal("This is a test", await file.StagedPath.ReadAllTextAsync());
|
||||
|
||||
cleanup();
|
||||
await cleanup();
|
||||
}
|
||||
|
||||
private static async Task AddFile(AbsolutePath filename, string text)
|
||||
|
@ -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)
|
||||
.Distinct()
|
||||
@ -215,18 +215,18 @@ namespace Wabbajack.VirtualFileSystem
|
||||
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>();
|
||||
|
||||
}
|
||||
|
||||
|
||||
#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 static IndexRoot Empty = new IndexRoot();
|
||||
|
Loading…
Reference in New Issue
Block a user