chiark / gitweb /
bundles: Truncate bundle files before deleting them
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 16 May 2021 21:55:15 +0000 (22:55 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 13:58:58 +0000 (14:58 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bundles.rs
src/global.rs

index 4f46ab3001f66cc9fe3629e5d1d2af6674b2a0d9..14b676658f1539dad084f2686d1573d9e93f21f8 100644 (file)
@@ -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) {
index bc571fba88302ab871d939332bb89b0ee84a0dff..bf94ce0efb2115bb11d61805594b09a1c93ea7ee 100644 (file)
@@ -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<F>(rm: F, path: &str, desc: &str)
       where F: FnOnce(&str) -> Result<(), io::Error>
       {