From 065c14c9dc4948aea2c7b359df5831834b194baa Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 1 May 2021 19:56:09 +0100 Subject: [PATCH] global: Refactor destroy game best effort deleting Signed-off-by: Ian Jackson --- src/global.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/global.rs b/src/global.rs index fc712955..3b7ff0b3 100644 --- a/src/global.rs +++ b/src/global.rs @@ -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(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>, -- 2.30.2