From 8243758ccc5a2f106157645e1bd7417e91b4f38a Mon Sep 17 00:00:00 2001 From: kxxt Date: Sun, 5 May 2024 12:04:26 +0800 Subject: [PATCH] tracer: use BTreeMap to make env sorted --- src/printer.rs | 4 ++-- src/proc.rs | 16 ++++++++-------- src/tracer.rs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index c957d991..0bd30532 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -1,6 +1,6 @@ use std::{ cell::RefCell, - collections::HashMap, + collections::BTreeMap, ffi::OsStr, io::{self, Write}, path::Path, @@ -357,7 +357,7 @@ impl Printer { &self, state: &ProcessState, result: i64, - env: &HashMap, + env: &BTreeMap, cwd: &Path, ) -> color_eyre::Result<()> { // Preconditions: diff --git a/src/proc.rs b/src/proc.rs index 3600edd0..806642ef 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -3,7 +3,7 @@ use core::fmt; use std::{ borrow::Cow, - collections::{BTreeMap, HashMap, HashSet}, + collections::{BTreeMap, BTreeSet, HashSet}, ffi::CString, fmt::{Display, Formatter}, io::{self, BufRead, BufReader, Read}, @@ -290,9 +290,9 @@ pub fn parse_env_entry(item: &str) -> (&str, &str) { #[derive(Debug, Clone, PartialEq)] pub struct EnvDiff { - pub added: HashMap, - pub removed: HashSet, - pub modified: HashMap, + pub added: BTreeMap, + pub removed: BTreeSet, + pub modified: BTreeMap, } impl EnvDiff { @@ -301,9 +301,9 @@ impl EnvDiff { } } -pub fn diff_env(original: &HashMap, envp: &[String]) -> EnvDiff { - let mut added = HashMap::new(); - let mut modified = HashMap::new(); +pub fn diff_env(original: &BTreeMap, envp: &[String]) -> EnvDiff { + let mut added = BTreeMap::new(); + let mut modified = BTreeMap::new(); // Use str to avoid cloning all env vars let mut removed: HashSet<&str> = original.keys().map(|v| v.as_str()).collect(); for entry in envp.iter() { @@ -329,7 +329,7 @@ pub fn diff_env(original: &HashMap, envp: &[String]) -> EnvDiff #[derive(Debug, Clone)] pub struct BaselineInfo { pub cwd: PathBuf, - pub env: HashMap, + pub env: BTreeMap, pub fdinfo: FileDescriptorInfoCollection, } diff --git a/src/tracer.rs b/src/tracer.rs index daa7db21..e6fef179 100644 --- a/src/tracer.rs +++ b/src/tracer.rs @@ -1,5 +1,5 @@ use std::{ - collections::HashMap, + collections::BTreeMap, ffi::CString, io::{self, stdin}, os::fd::AsRawFd, @@ -724,7 +724,7 @@ impl Tracer { // This function does not take self due to borrow checker fn collect_exec_event( - env: &HashMap, + env: &BTreeMap, state: &ProcessState, result: i64, ) -> Box {