Skip to content

Commit b43c077

Browse files
committed
Cleanup: Only write log line if delete, allow exceptions
1 parent abf23fd commit b43c077

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ff-utils-winforms/Program.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ public static void Cleanup()
5151
{
5252
string[] split = dir.Name.Split('-');
5353
int daysOld = (DateTime.Now - new DateTime(split[0].GetInt(), split[1].GetInt(), split[2].GetInt())).Days;
54-
Logger.Log($"Cleanup: Log folder {dir.Name} is {daysOld} days old - Will {(daysOld <= keepLogsDays ? "Keep" : "Delete")}", true);
5554

5655
if (daysOld > keepLogsDays || dir.GetFiles("*", SearchOption.AllDirectories).Length < 1) // keep logs for 4 days
57-
dir.Delete(true);
56+
{
57+
Logger.Log($"Cleanup: Log folder {dir.Name} is {daysOld} days old - Will Delete", true);
58+
IoUtils.TryDeleteIfExists(dir.FullName);
59+
}
5860
}
5961

6062
IoUtils.DeleteContentsOfDir(Paths.GetSessionDataPath()); // Clear this session's temp files...
@@ -63,10 +65,12 @@ public static void Cleanup()
6365
{
6466
string[] split = dir.Name.Split('-');
6567
int daysOld = (DateTime.Now - new DateTime(split[0].GetInt(), split[1].GetInt(), split[2].GetInt())).Days;
66-
Logger.Log($"Cleanup: Log folder {dir.Name} is {daysOld} days old - Will {(daysOld <= keepSessionDataDays ? "Keep" : "Delete")}", true);
6768

6869
if (daysOld > keepSessionDataDays || dir.GetFiles("*", SearchOption.AllDirectories).Length < 1) // keep temp files for 2 days
69-
dir.Delete(true);
70+
{
71+
Logger.Log($"Cleanup: Session folder {dir.Name} is {daysOld} days old - Will Delete", true);
72+
IoUtils.TryDeleteIfExists(dir.FullName);
73+
}
7074
}
7175

7276
foreach (string file in IoUtils.GetFilesSorted(Paths.GetBinPath(), true, "*.log*"))

0 commit comments

Comments
 (0)