use super::SnapDriver;
use crate::BtmCfg;
use ruc::*;
pub(crate) struct Zfs;
pub(crate) fn batch_destroy_cmd(volume: &str, indexes: &[u64]) -> String {
let list = indexes
.iter()
.map(|i| i.to_string())
.collect::<Vec<_>>()
.join(",");
format!("zfs destroy {}@{}", volume, list)
}
impl SnapDriver for Zfs {
fn list_snapshots_cmd(cfg: &BtmCfg) -> String {
format!("zfs list -H -t snapshot -d 1 -o name {}", &cfg.volume)
}
fn parse_snapshot_line(cfg: &BtmCfg, line: &str) -> Option<u64> {
super::parse_exact_snapshot(&cfg.volume, line)
}
fn create_snapshot_cmd(volume: &str, idx: u64) -> String {
format!("zfs snapshot {}@{}", volume, idx)
}
fn rollback_cmd(volume: &str, idx: u64) -> String {
format!("zfs rollback -r {}@{}", volume, idx)
}
fn destroy_cmd(volume: &str, idx: u64) -> String {
format!("zfs destroy {}@{}", volume, idx)
}
fn check_volume_cmd(volume: &str) -> String {
format!("zfs list {}", volume)
}
fn destroy_snapshots(volume: &str, indexes: &[u64]) -> Result<()> {
super::destroy_batched::<Self>(volume, indexes, batch_destroy_cmd)
}
}