From: Ian Jackson Date: Sun, 16 May 2021 21:55:15 +0000 (+0100) Subject: bundles: Truncate bundle files before deleting them X-Git-Tag: otter-0.6.0~210 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=dd1fbdb88a550d10b794e245bf97ddae63dcf194;p=otter.git bundles: Truncate bundle files before deleting them Signed-off-by: Ian Jackson --- diff --git a/src/bundles.rs b/src/bundles.rs index 4f46ab30..14b67665 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -933,6 +933,33 @@ impl InstanceBundles { //---------- clearing ---------- impl InstanceBundles { + pub fn truncate_all_besteffort(instance: &InstanceName) { + if_let!{ + Ok(bundles) = InstanceBundles::scan_game_bundles(instance); + match Err(e) => { + error!("failed to scan game bundles for {}: {}", instance, e); + return; + } + }; + for entry in bundles { + if_let!{ + Ok((fpath,_what)) = entry; + match Err(e) => { + error!("failed to make sense of a pathname for {}: {}", instance, e); + continue; + } + }; + if_let!{ + Ok(_) = File::create(&fpath); + match Err(e) => { + warn!("failed to truncate a bundle for {}: {}: {}", + instance, fpath, e); + continue; + } + } + } + } + #[throws(MgmtError)] pub fn clear(&mut self, ig: &mut Instance) { @@ -984,6 +1011,8 @@ impl InstanceBundles { to_clean.push((&|p| fs::remove_file (p), tmp )); } + InstanceBundles::truncate_all_besteffort(&ig.name); + // Actually try to clean up WRECKAGE into NEARLY-ABSENT for (f,p) in to_clean { match f(&p) { diff --git a/src/global.rs b/src/global.rs index bc571fba..bf94ce0e 100644 --- a/src/global.rs +++ b/src/global.rs @@ -436,7 +436,8 @@ impl Instance { InstanceGuard::forget_all_tokens(&mut g.g.tokens_clients); InstanceGuard::forget_all_tokens(&mut g.g.tokens_players); - // xxx truncate bundles, part of ClearBundles too! + InstanceBundles::truncate_all_besteffort(&g.g.name); + fn best_effort(rm: F, path: &str, desc: &str) where F: FnOnce(&str) -> Result<(), io::Error> {