Pre Post transaction hooks for snapshots and such.

This commit is contained in:
2026-09-14 22:48:05 +02:00
parent 4a4e6927bd
commit 2fedcd0805
8 changed files with 98 additions and 34 deletions
+34
View File
@@ -34,6 +34,9 @@ const BOOT_MENU_LABEL_BACK: &str = "Kira OS Fallback";
const BOOT_UKI_IMAGE_NAME: &str = "\\EFI\\linux-kira-lts.efi";
const BOOT_UKI_IMAGE_NAME_BACK: &str = "\\EFI\\linux-kira-lts-back.efi";
const PAC_LOCK_FILE: &str = "/var/lib/hive-up/pac-lock";
#[derive(Debug)]
pub struct CommandFailed {
pub stderr: Vec<u8>,
@@ -227,6 +230,37 @@ pub fn snapshot_system() -> Result<String, ExecCommandError> {
Ok(local_time)
}
/// Function for pacman preTransaction hook
///
pub fn pac_start() -> Result<(), ExecCommandError> {
use std::path::Path;
// Check if lock file exist
let pack_lock_path = Path::new(PAC_LOCK_FILE);
if pack_lock_path.exists() {
println!("Warning! Pac Lock file exist, skipping system snapshot...");
return Ok(());
}
println!("Creating system snapshot...");
let snap_time = snapshot_system()?;
println!("Ok.");
fs::write(PAC_LOCK_FILE, snap_time)?;
Ok(())
}
pub fn pac_finish() -> Result<(), ExecCommandError> {
use std::path::Path;
// Check if lock file exist
let pack_lock_path = Path::new(PAC_LOCK_FILE);
if pack_lock_path.exists() {
println!("Remowing pac-lock...");
fs::remove_file(pack_lock_path)?;
}
else {
println!("Warning! Pac Lock file does not exist - something is wrong...");
}
Ok(())
}
//const TMP_ROOT: &str = "/mnt/bee-root";
// pub fn list_bzzpss_snaps() -> Result<Vec<String>, ExecCommandError> {
// use regex::Regex;
+11 -2
View File
@@ -21,7 +21,6 @@ use std::sync::Arc;
use std::sync::atomic::AtomicBool;
mod hive_system;
mod hive_config;
#[derive(Debug)]
@@ -92,6 +91,14 @@ enum BootCommand {
enum Pac {
/// Creates snapshoots of /usr and /var subvolumea
SnapshotSystem,
/// This supposed to be called by pacman hook before transaction
/// hive-up will check for /var/lib/hive-up/pac-lock and will not create snapshots in case it present
/// Its safe lock mesure to prevent multiple snapshots on system fixing or some corner cases
/// Lock file can be deleted by `pac finish` that should be called by pacman after transaction
Start,
/// This supposed to be called by pacman hook before transaction.
/// Right now only thing it does is removes /var/lib/hive-up/pac-lock file
Finis,
}
#[derive(Subcommand, Debug)]
@@ -158,7 +165,9 @@ fn main() -> Result<(), HiveUpError> {
println!("Creating system snapshot...");
let _ = hive_system::snapshot_system()?;
println!("Ok.");
}
},
Pac::Start => hive_system::pac_start()?,
Pac::Finis => hive_system::pac_finish()?
}
}