From d196662ac6789d8f483edb229fadec5d6b3daf20 Mon Sep 17 00:00:00 2001 From: James McDonald Date: Mon, 27 Apr 2026 20:46:04 +0200 Subject: [PATCH] Replace HashSet with IndexSet to preserve order Also clean up some match arms. --- Cargo.lock | 23 +++++++++++++++++++++++ Cargo.toml | 1 + src/job.rs | 32 ++++++++++++++++---------------- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 78a40b8..ca7dcea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,12 +154,24 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "find-msvc-tools" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +[[package]] +name = "hashbrown" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" + [[package]] name = "heck" version = "0.5.0" @@ -190,6 +202,16 @@ dependencies = [ "cc", ] +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -417,4 +439,5 @@ version = "0.2.3" dependencies = [ "chrono", "clap", + "indexmap", ] diff --git a/Cargo.toml b/Cargo.toml index 2837cff..d55c05d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ publish = false [dependencies] chrono = "0.4.44" clap = { version = "4.6.1", features = ["derive"] } +indexmap = "2.14.0" diff --git a/src/job.rs b/src/job.rs index e1ce9ee..fc95126 100644 --- a/src/job.rs +++ b/src/job.rs @@ -2,12 +2,13 @@ use crate::command; use crate::progress::BackupEvent; use crate::progress::filter; use chrono::{Local, NaiveDateTime}; +use indexmap::set::IndexSet; use std::collections::HashSet; use std::fmt; use std::sync::mpsc::Sender; pub struct Job { - datasets: HashSet, + datasets: IndexSet, target: String, source_zfs_command: Vec, target_zfs_command: Vec, @@ -284,24 +285,23 @@ fn parse_command(commandstr: &str) -> Vec { for c in commandstr.chars() { match c { + '\'' if !in_double_quote => { + in_single_quote = !in_single_quote; + } '\'' => { - if !in_double_quote { - in_single_quote = !in_single_quote; - } else { - arg.push(c); - } + arg.push(c); + } + '"' if !in_single_quote => { + in_double_quote = !in_double_quote; } '"' => { - if !in_single_quote { - in_double_quote = !in_double_quote; - } else { - arg.push(c); - } + arg.push(c); + } + ' ' if in_single_quote || in_double_quote => { + arg.push(c); } ' ' => { - if in_single_quote || in_double_quote { - arg.push(c); - } else if !arg.is_empty() { + if !arg.is_empty() { command.push(arg.clone()); arg.clear(); } @@ -362,7 +362,7 @@ impl JobBuilder { } pub fn build(self) -> Result { - let mut datasets: HashSet = HashSet::new(); + let mut datasets: IndexSet = IndexSet::new(); for source in &self.sources { let recurse = source.ends_with("/..."); let source = source.trim_end_matches("/..."); @@ -382,7 +382,7 @@ impl JobBuilder { return Err(String::from("no matching source datasets found")); } Ok(Job { - datasets: datasets, + datasets, target: self.target, source_zfs_command: self.source_zfs_command, target_zfs_command: self.target_zfs_command,