diff --git a/Cargo.lock b/Cargo.lock index 0de751e..4466638 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -644,6 +644,7 @@ dependencies = [ "color-eyre", "dotenvy", "glob", + "indexmap", "loopdev-fyra", "merge-struct", "nix", diff --git a/Cargo.toml b/Cargo.toml index 6b4abf1..e14f52a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,3 +38,4 @@ nix = { version = "0.27", features = ["mount", "hostname", "dir"] } uuid = { version = "1.4.1", features = ["v4", "serde"] } loopdev-fyra = { version = "0.5.0" } bytesize = { version = "1.3.0", features = ["serde"] } +indexmap = "2.2.6" diff --git a/src/builder.rs b/src/builder.rs index b6a2e73..5ff39fb 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -7,9 +7,10 @@ use crate::{ }; use cmd_lib::{run_cmd, run_fun}; use color_eyre::{eyre::bail, Result}; +use indexmap::IndexMap; use serde_derive::{Deserialize, Serialize}; use std::{ - collections::{BTreeMap, HashMap}, + collections::BTreeMap, fs, path::{Path, PathBuf}, }; @@ -406,13 +407,15 @@ pub fn run_script(script: Script, chroot: &Path, is_post: bool) -> Result<()> { pub fn run_all_scripts(scrs: &[Script], chroot: &Path, is_post: bool) -> Result<()> { // name => (Script, is_executed) + let mut scrs = scrs.to_owned(); + scrs.sort_by_cached_key(|s| s.priority); let scrs = scrs.iter().map(|s| (s.id.as_ref().map_or("", |s| s), (s.clone(), false))); run_scripts(scrs.collect(), chroot, is_post) } #[tracing::instrument] pub fn run_scripts( - mut scripts: HashMap<&str, (Script, bool)>, chroot: &Path, is_post: bool, + mut scripts: IndexMap<&str, (Script, bool)>, chroot: &Path, is_post: bool, ) -> Result<()> { trace!("Running scripts"); for idx in scripts.clone().keys() { @@ -426,7 +429,7 @@ pub fn run_scripts( // Find needs let id = scr.id.clone().unwrap_or("".into()); - let mut needs = HashMap::new(); + let mut needs = IndexMap::new(); let scr_needs_vec = &scr.needs.clone(); for need in scr_needs_vec { // when funny rust doesn't know how to convert &String to &str diff --git a/src/config.rs b/src/config.rs index ba7d451..e3acf58 100644 --- a/src/config.rs +++ b/src/config.rs @@ -204,6 +204,10 @@ pub struct ScriptsManifest { pub post: Vec