From fe0abc4a8fc596cf1c8e7e264ec02bf7cb0a5898 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sat, 9 Oct 2021 14:36:46 -0700 Subject: [PATCH] fix: Cleans up archiving and fixes wrong relative path used (#825) --- Projects/UOContent/Compression/ZstdArchive.cs | 10 ++++++---- Projects/UOContent/World Saves/AutoArchive.cs | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Projects/UOContent/Compression/ZstdArchive.cs b/Projects/UOContent/Compression/ZstdArchive.cs index b121e023a..53769f09d 100755 --- a/Projects/UOContent/Compression/ZstdArchive.cs +++ b/Projects/UOContent/Compression/ZstdArchive.cs @@ -14,7 +14,8 @@ namespace Server.Compression // bsdtar has a bug and hangs, so we are doing it in two steps. if (Core.IsWindows) { - var tempTarArchive = Path.Combine(Core.BaseDirectory, "temp/temp-file.tar"); + var tempDir = PathUtility.EnsureRandomPath(Path.GetTempPath()); + var tempTarArchive = Path.Combine(tempDir, "temp-file.tar"); try { @@ -54,11 +55,12 @@ namespace Server.Compression // bsdtar has a bug and hangs, so we are doing it in two steps. if (Core.IsWindows) { - var tempTarArchive = Path.Combine(Core.BaseDirectory, "temp/temp-file.tar"); + var tempDir = PathUtility.EnsureRandomPath(Path.GetTempPath()); + var tempTarArchive = Path.Combine(tempDir, "temp-file.tar"); try { - if (!TarArchive.CreateFromPaths(paths, relativeTo, tempTarArchive)) + if (!TarArchive.CreateFromPaths(paths, tempTarArchive, relativeTo)) { return false; } @@ -83,7 +85,7 @@ namespace Server.Compression } finally { - File.Delete(tempTarArchive); + Directory.Delete(tempDir, true); } } diff --git a/Projects/UOContent/World Saves/AutoArchive.cs b/Projects/UOContent/World Saves/AutoArchive.cs index ed4dd4afd..7d46d6168 100755 --- a/Projects/UOContent/World Saves/AutoArchive.cs +++ b/Projects/UOContent/World Saves/AutoArchive.cs @@ -314,7 +314,7 @@ namespace Server.Saves foreach (var (rangeStart, sortedBackups) in items) { var backups = sortedBackups.Values; - if (backups.Count == 0) + if (backups.Count <= minimum) { continue; } @@ -397,7 +397,9 @@ namespace Server.Saves if (TryGetDate(name, out var date)) { - items.Add(date, item); + // Might give wrong results if there is a file that matches: + // Example: 2021-09-01, and 2021-09-01-00 + items[date] = item; } } @@ -435,7 +437,6 @@ namespace Server.Saves } catch { - logger.Warning($"Path was not in the correct date format: {value}"); date = DateTime.MinValue; return false; }