From afd1daef4ce81b81cabd3957c1c444ac5e4b4956 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 9 Feb 2019 15:16:14 -0500 Subject: [PATCH] fix Save Backup not pruning old backups if they're uncompressed --- docs/release-notes.md | 3 +++ src/SMAPI.Mods.SaveBackup/ModEntry.cs | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 82df7ae6..caec3504 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,6 +2,9 @@ ## 3.0 (upcoming release) These changes have not been released yet. +* For players: + * Fixed Save Backup not pruning old backups if they're uncompressed. + * For modders: * Added `IContentPack.HasFile` method. * Updated to Json.NET 12.0.1. diff --git a/src/SMAPI.Mods.SaveBackup/ModEntry.cs b/src/SMAPI.Mods.SaveBackup/ModEntry.cs index d10131b3..8a83cb9d 100644 --- a/src/SMAPI.Mods.SaveBackup/ModEntry.cs +++ b/src/SMAPI.Mods.SaveBackup/ModEntry.cs @@ -124,20 +124,23 @@ namespace StardewModdingAPI.Mods.SaveBackup try { var oldBackups = backupFolder - .GetFiles() + .GetFileSystemInfos() .OrderByDescending(p => p.CreationTimeUtc) .Skip(backupsToKeep); - foreach (FileInfo file in oldBackups) + foreach (FileSystemInfo entry in oldBackups) { try { - this.Monitor.Log($"Deleting {file.Name}...", LogLevel.Trace); - file.Delete(); + this.Monitor.Log($"Deleting {entry.Name}...", LogLevel.Trace); + if (entry is DirectoryInfo folder) + folder.Delete(recursive: true); + else + entry.Delete(); } catch (Exception ex) { - this.Monitor.Log($"Error deleting old save backup '{file.Name}': {ex}"); + this.Monitor.Log($"Error deleting old save backup '{entry.Name}': {ex}"); } } }