Fix tests and implement basic hard link support

This commit is contained in:
Timothy Baldridge 2020-05-04 14:33:45 -06:00
parent 2be1771d89
commit 314c77a830
4 changed files with 33 additions and 3 deletions

View File

@ -6,6 +6,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Alphaleonis.Win32.Filesystem;
@ -340,6 +341,29 @@ namespace Wabbajack.Common
{
File.Copy(_path, dest._path);
}
[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)]
private static extern bool CreateHardLink(string lpFileName, string lpExistingFileName, IntPtr lpSecurityAttributes);
public bool HardLinkTo(AbsolutePath destination)
{
return CreateHardLink((string)destination, (string)this, IntPtr.Zero);
}
public static long HARDLINK_THRESHOLD = 2 ^ 29; // 512 MB
public async ValueTask HardLinkIfOversize(AbsolutePath destination)
{
if (Root == destination.Root || Size >= HARDLINK_THRESHOLD)
{
if (HardLinkTo(destination))
return;
}
await CopyToAsync(destination);
}
public async Task<IEnumerable<string>> ReadAllLinesAsync()
{

View File

@ -141,7 +141,7 @@ namespace Wabbajack.Lib
Status($"Copying files for {archive.Name}");
async ValueTask CopyFile(AbsolutePath from, AbsolutePath to, bool useMove)
async ValueTask CopyFile(VirtualFile? vf, AbsolutePath from, AbsolutePath to, bool useMove)
{
if (to.Exists)
{
@ -156,6 +156,11 @@ namespace Wabbajack.Lib
from.IsReadOnly = false;
}
if (vf!.IsNative && vf.AbsoluteName == from)
{
await from.HardLinkIfOversize(to);
return;
}
if (useMove)
from.MoveTo(to);
@ -180,7 +185,7 @@ namespace Wabbajack.Lib
foreach (var copy in group.Skip(1))
{
await CopyFile(firstDest, OutputFolder.Combine(copy.To), false);
await CopyFile(group.Key, firstDest, OutputFolder.Combine(copy.To), false);
}
});

View File

@ -15,6 +15,7 @@ namespace Wabbajack.Lib.WebAutomation
public Driver()
{
_browser = new ChromiumWebBrowser();
_driver = new CefSharpWrapper(_browser);
}
public static async Task<Driver> Create()

View File

@ -505,7 +505,7 @@ namespace Wabbajack.Test
await folder.DeleteDirectory();
folder.CreateDirectory();
var inst = new TestInstaller(default, null, default, folder, null);
var inst = new TestInstaller(default, new ModList {GameType = Game.SkyrimSpecialEdition}, default, folder, null);
await inst.DownloadMissingArchives(archivesa, true);
await inst.DownloadMissingArchives(archivesb, true);