From 77993884ac8be19946aa5a27464175185e9c61e5 Mon Sep 17 00:00:00 2001 From: ike709 Date: Fri, 29 Nov 2024 12:32:08 -0600 Subject: [PATCH 1/2] Fix recreating deleted savefiles --- OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs b/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs index 81feba9d27..5787ff702d 100644 --- a/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs +++ b/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs @@ -259,6 +259,7 @@ public void Close() { } public void Flush() { + if (Deleted) return; Resource!.Clear(); Resource!.Output(new DreamValue(JsonSerializer.Serialize(_rootNode))); } From ebb5c4ee394ef72b55e64598a774ee1e7363d341 Mon Sep 17 00:00:00 2001 From: ike709 Date: Sat, 30 Nov 2024 15:16:54 -0600 Subject: [PATCH 2/2] change the checks --- OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs b/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs index 5787ff702d..102fe44855 100644 --- a/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs +++ b/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs @@ -230,7 +230,8 @@ public static void FlushAllUpdates() { _sawmill ??= Logger.GetSawmill("opendream.res"); foreach (DreamObjectSavefile savefile in SavefilesToFlush) { try { - savefile.Flush(); + // We need to avoid Flush() recreating a nonexistent file + if (File.Exists(savefile.Resource!.ResourcePath)) savefile.Flush(); } catch (Exception e) { _sawmill.Error($"Error flushing savefile {savefile.Resource!.ResourcePath}: {e}"); } @@ -239,10 +240,12 @@ public static void FlushAllUpdates() { } public void Close() { - Flush(); + // We need to avoid Flush() recreating a nonexistent file + if (File.Exists(Resource!.ResourcePath)) Flush(); if (_isTemporary && Resource?.ResourcePath != null) { File.Delete(Resource.ResourcePath); } + //check to see if the file is still in use by another savefile datum if(Resource?.ResourcePath != null) { var fineToDelete = true; @@ -255,11 +258,12 @@ public void Close() { if (fineToDelete) SavefileDirectories.Remove(Resource.ResourcePath); } + Savefiles.Remove(this); + SavefilesToFlush.Remove(this); } public void Flush() { - if (Deleted) return; Resource!.Clear(); Resource!.Output(new DreamValue(JsonSerializer.Serialize(_rootNode))); }