Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recreating deleted savefiles #2114

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading