Skip to content

Commit 6b7651f

Browse files
Fix deleting cached files when setting has been enabled (#645)
* Fix deleting cached files when setting has been enabled * Replace `string=""` with `string.IsNullOrEmpty()` * Add file caching before delete * Improve `Apply` and `Revert` mechanism for `KeepChanges`
1 parent 383933d commit 6b7651f

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

DTAConfig/Settings/FileSourceDestinationInfo.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,12 @@ public void Apply()
102102
case FileOperationOption.KeepChanges:
103103
if (!File.Exists(DestinationPath))
104104
{
105-
SafePath.GetDirectory(Path.GetDirectoryName(CachedPath)).Create();
106-
107-
if (!File.Exists(CachedPath))
108-
File.Copy(SourcePath, CachedPath, true);
105+
if (File.Exists(CachedPath))
106+
File.Move(CachedPath, DestinationPath);
107+
else
108+
File.Copy(SourcePath, DestinationPath, true);
109109
}
110110

111-
FileHelper.CreateHardLinkFromSource(CachedPath, DestinationPath, fallback: true);
112-
113111
break;
114112

115113
case FileOperationOption.AlwaysOverwrite:
@@ -139,13 +137,10 @@ public void Revert()
139137
case FileOperationOption.KeepChanges:
140138
if (File.Exists(DestinationPath))
141139
{
142-
string cacheHash = Utilities.CalculateSHA1ForFile(CachedPath);
143-
string destinationHash = Utilities.CalculateSHA1ForFile(DestinationPath);
144-
145-
if (cacheHash != destinationHash)
146-
File.Copy(DestinationPath, CachedPath, true);
140+
if (!File.Exists(Path.GetDirectoryName(CachedPath)))
141+
SafePath.GetDirectory(Path.GetDirectoryName(CachedPath)).Create();
147142

148-
File.Delete(DestinationPath);
143+
File.Move(DestinationPath, CachedPath);
149144
}
150145
break;
151146

0 commit comments

Comments
 (0)