Skip to content

Commit b2d58dc

Browse files
committed
Use temp dir in instance for mod file transactions
1 parent 80fa5d1 commit b2d58dc

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

Core/GameInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private void SetupCkanDirectories()
7373
log.InfoFormat("Initialising {0}", CkanDir);
7474

7575
// TxFileManager knows if we are in a transaction
76-
var txFileMgr = new TxFileManager();
76+
var txFileMgr = new TxFileManager(CkanDir);
7777

7878
if (!Directory.Exists(CkanDir))
7979
{

Core/IO/ModuleInstaller.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ public ModuleInstaller(GameInstance inst,
3232
IUser user,
3333
CancellationToken cancelToken = default)
3434
{
35-
User = user;
36-
this.cache = cache;
37-
this.config = config;
38-
instance = inst;
35+
log.DebugFormat("Creating ModuleInstaller for {0}", inst.GameDir);
36+
instance = inst;
37+
// Make a transaction file manager that uses a temp dir in the instance's CKAN dir
38+
this.cache = cache;
39+
this.config = config;
40+
User = user;
3941
this.cancelToken = cancelToken;
40-
log.DebugFormat("Creating ModuleInstaller for {0}", instance.GameDir);
4142
}
4243

4344
public IUser User { get; set; }
@@ -394,7 +395,7 @@ private List<string> InstallModule(CkanModule
394395
// Delete the manually installed DLL transaction-style because we believe we'll be replacing it
395396
var toDelete = instance.ToAbsoluteGameDir(dll);
396397
log.DebugFormat("Deleting manually installed DLL {0}", toDelete);
397-
var txFileMgr = new TxFileManager();
398+
var txFileMgr = new TxFileManager(instance.CkanDir);
398399
txFileMgr.Snapshot(toDelete);
399400
txFileMgr.Delete(toDelete);
400401
}
@@ -543,9 +544,9 @@ private static bool StreamsEqual(Stream s1, Stream s2)
543544
/// fails at a later stage.
544545
/// </summary>
545546
/// <param name="files">The files to overwrite</param>
546-
private static void DeleteConflictingFiles(IEnumerable<InstallableFile> files)
547+
private void DeleteConflictingFiles(IEnumerable<InstallableFile> files)
547548
{
548-
var txFileMgr = new TxFileManager();
549+
var txFileMgr = new TxFileManager(instance.CkanDir);
549550
foreach (InstallableFile file in files)
550551
{
551552
log.DebugFormat("Trying to delete {0}", file.destination);
@@ -695,6 +696,16 @@ public static List<InstallableFile> FindInstallableFiles(CkanModule module,
695696

696697
#endregion
697698

699+
private string? InstallFile(ZipFile zipfile,
700+
ZipEntry entry,
701+
string fullPath,
702+
bool makeDirs,
703+
string[] candidateDuplicates,
704+
IProgress<long>? progress)
705+
=> InstallFile(zipfile, entry, fullPath, makeDirs,
706+
new TxFileManager(instance.CkanDir),
707+
candidateDuplicates, progress);
708+
698709
/// <summary>
699710
/// Copy the entry from the opened zipfile to the path specified.
700711
/// </summary>
@@ -707,11 +718,10 @@ public static List<InstallableFile> FindInstallableFiles(CkanModule module,
707718
ZipEntry entry,
708719
string fullPath,
709720
bool makeDirs,
721+
IFileManager txFileMgr,
710722
string[] candidateDuplicates,
711723
IProgress<long>? progress)
712724
{
713-
var txFileMgr = new TxFileManager();
714-
715725
if (entry.IsDirectory)
716726
{
717727
// Skip if we're not making directories for this install.
@@ -918,7 +928,7 @@ private void Uninstall(string identifier,
918928
Registry registry,
919929
IProgress<long> progress)
920930
{
921-
var txFileMgr = new TxFileManager();
931+
var txFileMgr = new TxFileManager(instance.CkanDir);
922932

923933
using (var transaction = CkanTransaction.CreateTransactionScope())
924934
{

Core/Registry/RegistryManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ private string Serialize()
388388

389389
public void Save(bool enforce_consistency = true)
390390
{
391-
var txFileMgr = new TxFileManager();
391+
var txFileMgr = new TxFileManager(gameInstance.CkanDir);
392392

393393
log.InfoFormat("Saving CKAN registry at {0}", path);
394394

@@ -444,7 +444,7 @@ private void ExportInstalled(IEnumerable<string> paths,
444444
bool recommends,
445445
bool withVersions)
446446
{
447-
var txFileMgr = new TxFileManager();
447+
var txFileMgr = new TxFileManager(gameInstance.CkanDir);
448448
var serialized = SerializeCurrentInstall(recommends, withVersions);
449449
foreach (var path in paths)
450450
{

Tests/Core/IO/ModuleInstallerTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net;
88

99
using ICSharpCode.SharpZipLib.Zip;
10+
using ChinhDo.Transactions;
1011
using NUnit.Framework;
1112
using WireMock.Server;
1213
using WireMock.RequestBuilders;
@@ -330,7 +331,7 @@ public void DontOverWrite_208()
330331

331332
Assert.Throws<FileExistsKraken>(delegate
332333
{
333-
ModuleInstaller.InstallFile(zipfile, entry, tmpfile, false, Array.Empty<string>(), null);
334+
ModuleInstaller.InstallFile(zipfile, entry, tmpfile, false, new TxFileManager(), Array.Empty<string>(), null);
334335
});
335336

336337
// Cleanup
@@ -368,7 +369,7 @@ private static string CopyDogeFromZip()
368369

369370
// We have to delete our temporary file, as CZE refuses to overwrite; huzzah!
370371
File.Delete(tmpfile);
371-
ModuleInstaller.InstallFile(zipfile, entry, tmpfile, false, Array.Empty<string>(), null);
372+
ModuleInstaller.InstallFile(zipfile, entry, tmpfile, false, new TxFileManager(), Array.Empty<string>(), null);
372373

373374
return tmpfile;
374375
}

0 commit comments

Comments
 (0)