safe-fail if old file can't be deleted

This commit is contained in:
Pilzinsel64
2024-10-11 11:19:08 +02:00
parent f2a901ada7
commit 540f14da0d

View File

@@ -25,6 +25,7 @@ public static class Utils
var triesLeft = 1; var triesLeft = 1;
var srcFileName = sourceFile.FullName; var srcFileName = sourceFile.FullName;
var destFileName = destinationFile.FullName; var destFileName = destinationFile.FullName;
string? oldFile = null;
while (triesLeft > 0) while (triesLeft > 0)
{ {
@@ -38,9 +39,8 @@ public static class Utils
{ {
if (triesLeft == 0 && File.Exists(destFileName)) if (triesLeft == 0 && File.Exists(destFileName))
{ {
var oldFile = destFileName + ".old"; oldFile = destFileName + ".old";
File.Move(destFileName, oldFile, true); File.Move(destFileName, oldFile, true);
File.Delete(oldFile);
triesLeft++; triesLeft++;
} }
} }
@@ -48,5 +48,16 @@ public static class Utils
{ {
} }
} }
if (oldFile != null)
{
try
{
File.Delete(oldFile);
}
catch (Exception)
{
}
}
} }
} }