mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #879 from wabbajack-tools/make-delete-async
Make all delete operations async
This commit is contained in:
commit
8a03fe7384
@ -12,7 +12,7 @@ namespace Wabbajack.Common.Test
|
|||||||
await tempFile.Path.WriteAllTextAsync("Test");
|
await tempFile.Path.WriteAllTextAsync("Test");
|
||||||
tempFile.Path.SetReadOnly(true);
|
tempFile.Path.SetReadOnly(true);
|
||||||
|
|
||||||
tempFile.Path.Delete();
|
await tempFile.Path.DeleteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -32,6 +32,30 @@ namespace Wabbajack.Common
|
|||||||
goto TOP;
|
goto TOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async ValueTask WithAutoRetry<TE>(Func<ValueTask> f, TimeSpan? delay = null, int? multipler = null, int? maxRetries = null) where TE : Exception
|
||||||
|
{
|
||||||
|
int retries = 0;
|
||||||
|
delay ??= DEFAULT_DELAY;
|
||||||
|
multipler ??= DEFAULT_DELAY_MULTIPLIER;
|
||||||
|
maxRetries ??= DEFAULT_RETRIES;
|
||||||
|
|
||||||
|
TOP:
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await f();
|
||||||
|
}
|
||||||
|
catch (TE ex)
|
||||||
|
{
|
||||||
|
retries += 1;
|
||||||
|
if (retries > maxRetries)
|
||||||
|
throw;
|
||||||
|
Utils.Log($"(Retry {retries} of {maxRetries}), got exception {ex.Message}, waiting {delay.Value.TotalMilliseconds}ms");
|
||||||
|
await Task.Delay(delay.Value);
|
||||||
|
delay = delay * multipler;
|
||||||
|
goto TOP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,10 +181,10 @@ namespace Wabbajack.Common
|
|||||||
if (Root != otherPath.Root)
|
if (Root != otherPath.Root)
|
||||||
{
|
{
|
||||||
if (otherPath.Exists && overwrite)
|
if (otherPath.Exists && overwrite)
|
||||||
otherPath.Delete();
|
await otherPath.DeleteAsync();
|
||||||
|
|
||||||
await CopyToAsync(otherPath);
|
await CopyToAsync(otherPath);
|
||||||
Delete();
|
await DeleteAsync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File.Move(_path, otherPath._path, overwrite ? MoveOptions.ReplaceExisting : MoveOptions.None);
|
File.Move(_path, otherPath._path, overwrite ? MoveOptions.ReplaceExisting : MoveOptions.None);
|
||||||
@ -248,13 +248,14 @@ namespace Wabbajack.Common
|
|||||||
Directory.CreateDirectory(_path);
|
Directory.CreateDirectory(_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Delete()
|
public async Task DeleteAsync()
|
||||||
{
|
{
|
||||||
if (!IsFile) return;
|
if (!IsFile) return;
|
||||||
|
|
||||||
if (IsReadOnly) IsReadOnly = false;
|
if (IsReadOnly) IsReadOnly = false;
|
||||||
|
|
||||||
File.Delete(_path);
|
var path = _path;
|
||||||
|
await CircuitBreaker.WithAutoRetry<IOException>(async () => File.Delete(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool InFolder(AbsolutePath folder)
|
public bool InFolder(AbsolutePath folder)
|
||||||
|
@ -89,7 +89,7 @@ namespace Wabbajack.Common
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
f.Delete();
|
f.DeleteAsync().Wait();
|
||||||
success++;
|
success++;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -801,7 +801,7 @@ namespace Wabbajack.Common
|
|||||||
}
|
}
|
||||||
catch (UnauthorizedAccessException)
|
catch (UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
tmpName.Delete();
|
await tmpName.DeleteAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -929,7 +929,7 @@ namespace Wabbajack.Common
|
|||||||
size += buffer.Length;
|
size += buffer.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.Delete();
|
await file.DeleteAsync();
|
||||||
return size;
|
return size;
|
||||||
});
|
});
|
||||||
return results.Sum() / seconds;
|
return results.Sum() / seconds;
|
||||||
@ -1086,9 +1086,9 @@ namespace Wabbajack.Common
|
|||||||
.DistinctUntilChanged();
|
.DistinctUntilChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DeleteEncryptedJson(string key)
|
public static async ValueTask DeleteEncryptedJson(string key)
|
||||||
{
|
{
|
||||||
Consts.LocalAppDataPath.Combine(key).Delete();
|
await Consts.LocalAppDataPath.Combine(key).DeleteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StartProcessFromFile(string file)
|
public static void StartProcessFromFile(string file)
|
||||||
|
@ -147,7 +147,7 @@ namespace Wabbajack.Lib
|
|||||||
using (var of = await ModListOutputFolder.Combine("modlist").Create())
|
using (var of = await ModListOutputFolder.Combine("modlist").Create())
|
||||||
ModList.ToJson(of);
|
ModList.ToJson(of);
|
||||||
|
|
||||||
ModListOutputFile.Delete();
|
await ModListOutputFile.DeleteAsync();
|
||||||
|
|
||||||
using (var fs = await ModListOutputFile.Create())
|
using (var fs = await ModListOutputFile.Create())
|
||||||
{
|
{
|
||||||
|
@ -148,7 +148,7 @@ namespace Wabbajack.Lib
|
|||||||
{
|
{
|
||||||
if (to.IsReadOnly)
|
if (to.IsReadOnly)
|
||||||
to.IsReadOnly = false;
|
to.IsReadOnly = false;
|
||||||
to.Delete();
|
await to.DeleteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from.Exists)
|
if (from.Exists)
|
||||||
@ -210,7 +210,7 @@ namespace Wabbajack.Lib
|
|||||||
var oldData = new MemoryStream(await toFile.ReadAllBytesAsync());
|
var oldData = new MemoryStream(await toFile.ReadAllBytesAsync());
|
||||||
|
|
||||||
// Remove the file we're about to patch
|
// Remove the file we're about to patch
|
||||||
toFile.Delete();
|
await toFile.DeleteAsync();
|
||||||
|
|
||||||
// Patch it
|
// Patch it
|
||||||
await using (var outStream = await toFile.Create())
|
await using (var outStream = await toFile.Create())
|
||||||
@ -264,7 +264,7 @@ namespace Wabbajack.Lib
|
|||||||
var ext = Path.GetExtension(archive.Name);
|
var ext = Path.GetExtension(archive.Name);
|
||||||
var uniqueKey = archive.State.PrimaryKeyString.StringSha256Hex();
|
var uniqueKey = archive.State.PrimaryKeyString.StringSha256Hex();
|
||||||
outputPath = DownloadFolder.Combine(origName + "_" + uniqueKey + "_" + ext);
|
outputPath = DownloadFolder.Combine(origName + "_" + uniqueKey + "_" + ext);
|
||||||
outputPath.Delete();
|
await outputPath.DeleteAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +358,7 @@ namespace Wabbajack.Lib
|
|||||||
|
|
||||||
UpdateTracker.NextStep("Looking for files to delete");
|
UpdateTracker.NextStep("Looking for files to delete");
|
||||||
await OutputFolder.EnumerateFiles()
|
await OutputFolder.EnumerateFiles()
|
||||||
.PMap(Queue, UpdateTracker, f =>
|
.PMap(Queue, UpdateTracker, async f =>
|
||||||
{
|
{
|
||||||
var relativeTo = f.RelativeTo(OutputFolder);
|
var relativeTo = f.RelativeTo(OutputFolder);
|
||||||
Utils.Status($"Checking if ModList file {relativeTo}");
|
Utils.Status($"Checking if ModList file {relativeTo}");
|
||||||
@ -366,7 +366,7 @@ namespace Wabbajack.Lib
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Utils.Log($"Deleting {relativeTo} it's not part of this ModList");
|
Utils.Log($"Deleting {relativeTo} it's not part of this ModList");
|
||||||
f.Delete();
|
await f.DeleteAsync();
|
||||||
});
|
});
|
||||||
|
|
||||||
Utils.Log("Cleaning empty folders");
|
Utils.Log("Cleaning empty folders");
|
||||||
|
@ -43,7 +43,7 @@ namespace Wabbajack.Lib.Downloaders
|
|||||||
public BethesdaNetDownloader()
|
public BethesdaNetDownloader()
|
||||||
{
|
{
|
||||||
TriggerLogin = ReactiveCommand.CreateFromTask(() => Utils.CatchAndLog(RequestLoginAndCache), IsLoggedIn.Select(b => !b).ObserveOn(RxApp.MainThreadScheduler));
|
TriggerLogin = ReactiveCommand.CreateFromTask(() => Utils.CatchAndLog(RequestLoginAndCache), IsLoggedIn.Select(b => !b).ObserveOn(RxApp.MainThreadScheduler));
|
||||||
ClearLogin = ReactiveCommand.Create(() => Utils.DeleteEncryptedJson(DataName), IsLoggedIn.ObserveOn(RxApp.MainThreadScheduler));
|
ClearLogin = ReactiveCommand.Create(() => Utils.CatchAndLog(() =>Utils.DeleteEncryptedJson(DataName)), IsLoggedIn.ObserveOn(RxApp.MainThreadScheduler));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task RequestLoginAndCache()
|
private static async Task RequestLoginAndCache()
|
||||||
|
@ -233,7 +233,7 @@ namespace Wabbajack.Lib
|
|||||||
{
|
{
|
||||||
Status($"Writing included .meta file {directive.To}");
|
Status($"Writing included .meta file {directive.To}");
|
||||||
var outPath = DownloadFolder.Combine(directive.To);
|
var outPath = DownloadFolder.Combine(directive.To);
|
||||||
if (outPath.IsFile) outPath.Delete();
|
if (outPath.IsFile) await outPath.DeleteAsync();
|
||||||
await outPath.WriteAllBytesAsync(await LoadBytesFromPath(directive.SourceDataID));
|
await outPath.WriteAllBytesAsync(await LoadBytesFromPath(directive.SourceDataID));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -296,7 +296,7 @@ namespace Wabbajack.Lib
|
|||||||
{
|
{
|
||||||
Status($"Writing included file {directive.To}");
|
Status($"Writing included file {directive.To}");
|
||||||
var outPath = OutputFolder.Combine(directive.To);
|
var outPath = OutputFolder.Combine(directive.To);
|
||||||
outPath.Delete();
|
await outPath.DeleteAsync();
|
||||||
|
|
||||||
switch (directive)
|
switch (directive)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ namespace Wabbajack.Server.Services
|
|||||||
var hash = await file.FileHashAsync();
|
var hash = await file.FileHashAsync();
|
||||||
if (HaveArchive(hash))
|
if (HaveArchive(hash))
|
||||||
{
|
{
|
||||||
file.Delete();
|
await file.DeleteAsync();
|
||||||
return _archives[hash];
|
return _archives[hash];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ namespace Wabbajack.Test
|
|||||||
DownloadAndInstall(Game.SkyrimSpecialEdition, 32359, "Frost Armor HDT"));
|
DownloadAndInstall(Game.SkyrimSpecialEdition, 32359, "Frost Armor HDT"));
|
||||||
|
|
||||||
// We're going to fully patch this mod from another source.
|
// We're going to fully patch this mod from another source.
|
||||||
modfiles[3].Download.Delete();
|
await modfiles[3].Download.DeleteAsync();
|
||||||
|
|
||||||
await utils.Configure();
|
await utils.Configure();
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ namespace Wabbajack.Test
|
|||||||
|
|
||||||
Assert.Equal(server.Data, await testFile.Path.ReadAllBytesAsync());
|
Assert.Equal(server.Data, await testFile.Path.ReadAllBytesAsync());
|
||||||
|
|
||||||
testFile.Path.Delete();
|
await testFile.Path.DeleteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -164,7 +164,7 @@ namespace Wabbajack.Test
|
|||||||
await modifiedPath.WriteAllTextAsync("random data");
|
await modifiedPath.WriteAllTextAsync("random data");
|
||||||
var modifiedModified = modifiedPath.LastModified;
|
var modifiedModified = modifiedPath.LastModified;
|
||||||
|
|
||||||
deletedPath.Delete();
|
await deletedPath.DeleteAsync();
|
||||||
|
|
||||||
Assert.True(extraPath.Exists);
|
Assert.True(extraPath.Exists);
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ namespace Wabbajack.VirtualFileSystem.Test
|
|||||||
Assert.Equal(14, file.Size);
|
Assert.Equal(14, file.Size);
|
||||||
Assert.Equal(Hash.FromBase64("qX0GZvIaTKM="), file.Hash);
|
Assert.Equal(Hash.FromBase64("qX0GZvIaTKM="), file.Hash);
|
||||||
|
|
||||||
TEST_TXT.Delete();
|
await TEST_TXT.DeleteAsync();
|
||||||
|
|
||||||
await AddTestRoot();
|
await AddTestRoot();
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ namespace Wabbajack.VirtualFileSystem
|
|||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
{
|
{
|
||||||
filename.Delete();
|
await filename.DeleteAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,10 +50,10 @@ namespace Wabbajack
|
|||||||
}
|
}
|
||||||
|
|
||||||
var backup = Consts.SettingsFile.AppendToName("-backup");
|
var backup = Consts.SettingsFile.AppendToName("-backup");
|
||||||
backup.Delete();
|
await backup.DeleteAsync();
|
||||||
|
|
||||||
await Consts.SettingsFile.CopyToAsync(backup);
|
await Consts.SettingsFile.CopyToAsync(backup);
|
||||||
Consts.SettingsFile.Delete();
|
await Consts.SettingsFile.DeleteAsync();
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user