chiark / gitweb /
global: Refactor destroy game best effort deleting
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 1 May 2021 18:56:09 +0000 (19:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 1 May 2021 18:56:09 +0000 (19:56 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/global.rs

index fc7129554bafb72d11e9b64de43847b994c15f17..3b7ff0b3cce6d01fdd21c234a839d671b54cae65 100644 (file)
@@ -414,17 +414,21 @@ impl Instance {
       games.remove(&g.g.name);
       InstanceGuard::forget_all_tokens(&mut g.g.tokens_clients);
       InstanceGuard::forget_all_tokens(&mut g.g.tokens_players);
-    })(); // <- No ?, ensures that IEFE is infallible (barring panics)
 
-    (||{ // Best effort:
-      fs::remove_file(&a_savefile)
-    })()
-      .unwrap_or_else(
-        |e| warn!("failed to delete stale auth file {:?}: {:?}",
-                  &a_savefile, e)
-        // apart from that, ignore the error
-        // load_games will clean it up later.
-      );
+      fn best_effort<F>(rm: F, path: &str, desc: &str)
+      where F: FnOnce(&str) -> Result<(), io::Error>
+      {
+        rm(path)
+          .unwrap_or_else(
+            |e| warn!("failed to delete stale {} {:?}: {:?}",
+                      desc, path, e)
+            // apart from that, ignore the error
+            // load_games will clean it up later.
+          );
+      }
+      best_effort(|f| fs::remove_file(f), &a_savefile, "auth file");
+
+    })(); // <- No ?, ensures that IEFE is infallible (barring panics)
   }
 
   pub fn list_names(account: Option<&AccountName>,