Skip to content

Commit

Permalink
Fix recreating deleted savefiles (#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ike709 authored Nov 30, 2024
1 parent 4e310e9 commit b9bfd6a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Expand All @@ -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;
Expand All @@ -255,7 +258,9 @@ public void Close() {
if (fineToDelete)
SavefileDirectories.Remove(Resource.ResourcePath);
}

Savefiles.Remove(this);
SavefilesToFlush.Remove(this);
}

public void Flush() {
Expand Down

0 comments on commit b9bfd6a

Please sign in to comment.