poudboot/src/action/ports_tree.rs
2024-05-05 10:27:08 -04:00

26 lines
867 B
Rust

use std::process::Command;
use std::time::Duration;
use std::time::SystemTime;
use crate::db::DbHandle;
pub(crate) const ACTION_UPDATE_PORTS_TREE: &str = "update_ports_tree";
const ACTION_UPDATE_PORTS_TREE_INTERVAL: u64 = 86400;
pub(crate) fn update_ports_tree(db_conn: &mut DbHandle) -> Result<(), Box<dyn std::error::Error>> {
println!("Updating ports tree.");
Command::new("portshaker").arg("-U").status()?.exit_ok()?;
Command::new("portshaker").arg("-M").status()?.exit_ok()?;
let next_run = (SystemTime::now() + Duration::from_secs(ACTION_UPDATE_PORTS_TREE_INTERVAL))
.duration_since(SystemTime::UNIX_EPOCH)?
.as_secs();
let tx = db_conn.conn.transaction()?;
tx.execute(
"UPDATE global_action SET next_run=$1 WHERE name=$2",
(next_run, ACTION_UPDATE_PORTS_TREE),
)?;
tx.commit()?;
Ok(())
}