@@ -553,7 +553,7 @@ public async Task RunActions(Dictionary<GamePath, SyncNode> syncTree, GameInstal
553
553
var gameMetadataId = gameInstallation . GameMetadataId ;
554
554
var gameMetadata = GameInstallMetadata . Load ( Connection . Db , gameMetadataId ) ;
555
555
var register = gameInstallation . LocationsRegister ;
556
- var deletedFiles = new HashSet < ( GamePath GamePath , AbsolutePath FullPath ) > ( ) ;
556
+ HashSet < ( GamePath GamePath , AbsolutePath FullPath ) > foldersWithDeletedFiles = [ ] ;
557
557
558
558
foreach ( var action in ActionsInOrder )
559
559
{
@@ -574,7 +574,7 @@ public async Task RunActions(Dictionary<GamePath, SyncNode> syncTree, GameInstal
574
574
break ;
575
575
576
576
case Actions . DeleteFromDisk :
577
- ActionDeleteFromDisk ( syncTree , register , tx , gameInstallation . GameMetadataId , deletedFiles ) ;
577
+ ActionDeleteFromDisk ( syncTree , register , tx , gameInstallation . GameMetadataId , foldersWithDeletedFiles ) ;
578
578
break ;
579
579
580
580
case Actions . ExtractToDisk :
@@ -608,7 +608,15 @@ public async Task RunActions(Dictionary<GamePath, SyncNode> syncTree, GameInstal
608
608
}
609
609
tx . Add ( gameMetadataId , GameInstallMetadata . LastScannedDiskStateTransaction , EntityId . From ( tx . ThisTxId . Value ) ) ;
610
610
611
- await tx . Commit ( ) ;
611
+ var result = await tx . Commit ( ) ;
612
+
613
+ var newMetadata = gameMetadata . Rebase ( result . Db ) ;
614
+
615
+ // Clean up empty directories
616
+ if ( foldersWithDeletedFiles . Count > 0 )
617
+ {
618
+ CleanDirectories ( foldersWithDeletedFiles , newMetadata . DiskStateEntries , gameInstallation ) ;
619
+ }
612
620
}
613
621
614
622
private void WarnOfConflict ( Dictionary < GamePath , SyncNode > tree )
@@ -757,12 +765,13 @@ private void ActionDeleteFromDisk(Dictionary<GamePath, SyncNode> groupings, IGam
757
765
continue ;
758
766
var resolvedPath = register . GetResolvedPath ( path ) ;
759
767
resolvedPath . Delete ( ) ;
760
- foldersWithDeletedFiles . Add ( ( path , resolvedPath . Parent ) ) ;
761
768
762
769
763
- // Don't delete the entry if we're just going to replace it
770
+ // Only delete the entry if we're not going to replace it
764
771
if ( ! node . Actions . HasFlag ( Actions . ExtractToDisk ) )
765
772
{
773
+ foldersWithDeletedFiles . Add ( ( path , resolvedPath . Parent ) ) ;
774
+
766
775
var id = node . Disk . EntityId ;
767
776
tx . Retract ( id , DiskStateEntry . Path , ( ( EntityId ) gameMetadataId , path . LocationId , path . Path ) ) ;
768
777
tx . Retract ( id , DiskStateEntry . Hash , node . Disk . Hash ) ;
@@ -828,7 +837,6 @@ private bool ActionIngestFromDisk(Dictionary<GamePath, SyncNode> syncTree, Loado
828
837
var prevLoadout = Loadout . Load ( loadout . Db , lastAppliedId ) ;
829
838
if ( prevLoadout . IsValid ( ) )
830
839
{
831
- await Synchronize ( prevLoadout ) ;
832
840
await DeactivateCurrentLoadout ( loadout . InstallationInstance ) ;
833
841
await ActivateLoadout ( loadout ) ;
834
842
return loadout . Rebase ( ) ;
0 commit comments