Merge pull request #203 from wabbajack-tools/fix-directory-deleting

Switch directory deleting back to use a shell process. It's the only …
This commit is contained in:
Timothy Baldridge 2019-11-23 10:43:49 -07:00 committed by GitHub
commit 810b87de20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 55 additions and 13 deletions

View File

@ -95,8 +95,7 @@ namespace Compression.BSA.Test
{
TestContext.WriteLine($"From {bsa}");
TestContext.WriteLine("Cleaning Output Dir");
if (Directory.Exists(_tempDir)) Directory.Delete(_tempDir, true);
//if (Directory.Exists(ArchiveTempDir)) Directory.Delete(ArchiveTempDir, true);
if (Directory.Exists(_tempDir)) Utils.DeleteDirectory(_tempDir);
Directory.CreateDirectory(_tempDir);
TestContext.WriteLine($"Reading {bsa}");

View File

@ -825,5 +825,48 @@ namespace Wabbajack.Common
}
return ErrorResponse.Success;
}
/// <summary>
/// Both AlphaFS and C#'s Directory.Delete sometimes fail when certain files are read-only
/// or have other weird attributes. This is the only 100% reliable way I've found to completely
/// delete a folder. If you don't like this code, it's unlikely to change without a ton of testing.
/// </summary>
/// <param name="path"></param>
public static void DeleteDirectory(string path)
{
var info = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c del /f /q /s \"{path}\" && rmdir /q /s \"{path}\" ",
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
var p = new Process
{
StartInfo = info
};
p.Start();
ChildProcessTracker.AddProcess(p);
try
{
p.PriorityClass = ProcessPriorityClass.BelowNormal;
}
catch (Exception)
{
}
while (!p.HasExited)
{
var line = p.StandardOutput.ReadLine();
if (line == null) break;
Status(line);
}
p.WaitForExit();
}
}
}

View File

@ -119,7 +119,7 @@ namespace Wabbajack.Lib
Utils.Log("Removing ModList staging folder");
Directory.Delete(ModListOutputFolder, true);
Utils.DeleteDirectory(ModListOutputFolder);
}
public void ShowReport()

View File

@ -107,7 +107,7 @@ namespace Wabbajack.Lib
UpdateTracker.NextStep("Cleaning output folder");
if (Directory.Exists(ModListOutputFolder))
Directory.Delete(ModListOutputFolder, true, true);
Utils.DeleteDirectory(ModListOutputFolder);
UpdateTracker.NextStep("Finding Install Files");
Directory.CreateDirectory(ModListOutputFolder);

View File

@ -196,7 +196,7 @@ namespace Wabbajack.Lib
if (Directory.Exists(bsaDir))
{
Info($"Removing temp folder {Consts.BSACreationDir}");
Directory.Delete(bsaDir, true, true);
Utils.DeleteDirectory(bsaDir);
}
}

View File

@ -76,7 +76,7 @@ namespace Wabbajack.Lib
AddExternalFolder();
Info("Cleaning output folder");
if (Directory.Exists(ModListOutputFolder)) Directory.Delete(ModListOutputFolder, true);
if (Directory.Exists(ModListOutputFolder)) Utils.DeleteDirectory(ModListOutputFolder);
Directory.CreateDirectory(ModListOutputFolder);
IEnumerable<RawSourceFile> vortexStagingFiles = Directory.EnumerateFiles(StagingFolder, "*", SearchOption.AllDirectories)

View File

@ -69,7 +69,7 @@ namespace Wabbajack.Test
var loot_folder = Path.Combine(utils.InstallFolder, "LOOT Config Files");
if (Directory.Exists(loot_folder))
Directory.Delete(loot_folder, true);
Utils.DeleteDirectory(loot_folder);
var compiler = new MO2Compiler(utils.InstallFolder);
compiler.MO2DownloadsFolder = Path.Combine(utils.DownloadsFolder);

View File

@ -113,7 +113,7 @@ namespace Wabbajack.Test
public void Dispose()
{
var exts = new [] {".md", ".exe"};
Directory.Delete(Path.Combine(WorkingDirectory, ID), true);
Utils.DeleteDirectory(Path.Combine(WorkingDirectory, ID));
Profiles.Do(p =>
{
foreach (var ext in exts) {

View File

@ -24,7 +24,7 @@ namespace Wabbajack.VirtualFileSystem.Test
{
Utils.LogMessages.Subscribe(f => TestContext.WriteLine(f));
if (Directory.Exists(VFS_TEST_DIR))
Directory.Delete(VFS_TEST_DIR, true);
Utils.DeleteDirectory(VFS_TEST_DIR);
Directory.CreateDirectory(VFS_TEST_DIR);
Queue = new WorkQueue();
context = new Context(Queue);
@ -205,7 +205,7 @@ namespace Wabbajack.VirtualFileSystem.Test
{
var path = Path.Combine(VFS_TEST_DIR, folder);
ZipFile.CreateFromDirectory(path, Path.Combine(VFS_TEST_DIR, output));
Directory.Delete(path, true);
Utils.DeleteDirectory(path);
}
}
}
}

View File

@ -227,7 +227,7 @@ namespace Wabbajack.VirtualFileSystem
paths.Do(p =>
{
if (Directory.Exists(p))
Directory.Delete(p, true, true);
Utils.DeleteDirectory(p);
});
};
}
@ -417,7 +417,7 @@ namespace Wabbajack.VirtualFileSystem
public void Dispose()
{
Directory.Delete(FullName, true, true);
Utils.DeleteDirectory(FullName);
}
}
}