aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2024-01-28 17:03:55 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2024-01-28 17:04:21 +0100
commite1887c5d904ecbb0563b60ddc946dd71723cbc36 (patch)
treedf6868f9388588546af77d4549d571a5ced26392
parent178af2ede15e567307855f4003722ddd5e2d5b47 (diff)
deinitialization: remove snapshot subvolume recursively
-rw-r--r--hbak_common/src/system.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/hbak_common/src/system.rs b/hbak_common/src/system.rs
index e914824..bd43fef 100644
--- a/hbak_common/src/system.rs
+++ b/hbak_common/src/system.rs
@@ -3,6 +3,7 @@ use crate::proto::{BACKUP_DIR, SNAPSHOT_DIR};
use crate::LocalNodeError;
use std::fs;
+use std::io::BufRead;
use std::net::SocketAddr;
use std::path::Path;
use std::process::Command;
@@ -118,6 +119,38 @@ fn deinit_btrfs() -> Result<(), LocalNodeError> {
return Err(LocalNodeError::BtrfsCmd);
}
+ let output = Command::new("btrfs")
+ .arg("subvolume")
+ .arg("list")
+ .arg("-o")
+ .arg(SNAPSHOT_DIR)
+ .output()?;
+ if !output.status.success() {
+ return Err(LocalNodeError::BtrfsCmd);
+ }
+
+ let subvols = output.stdout.lines().map(|line| match line {
+ Ok(line) => Ok(Path::new(MOUNTPOINT).join(
+ line.split_whitespace()
+ .next_back()
+ .expect("String splitting yields at least one item"),
+ )),
+ Err(e) => Err(e),
+ });
+
+ for subvol in subvols {
+ if !Command::new("btrfs")
+ .arg("subvolume")
+ .arg("delete")
+ .arg(subvol?)
+ .spawn()?
+ .wait()?
+ .success()
+ {
+ return Err(LocalNodeError::BtrfsCmd);
+ }
+ }
+
if !Command::new("btrfs")
.arg("subvolume")
.arg("delete")