From 868ca7237ad94f9a0f4b443fe97e683e288a43d5 Mon Sep 17 00:00:00 2001 From: xml Date: Mon, 29 Apr 2024 16:19:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dnode=E5=86=99=E5=85=A5?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=AF=BC=E8=87=B4=E7=A8=8B=E5=BA=8F=E7=BB=88?= =?UTF-8?q?=E6=AD=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.rs | 2 +- src/main.rs | 8 ++++++-- src/utils.rs | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 01be61a..ad8d647 100644 --- a/src/config.rs +++ b/src/config.rs @@ -48,7 +48,7 @@ impl Config { match &self.value { Some(val) => { let raw_val = (self.handler)(&val); - crate::utils::write_line(&self.node, &raw_val).unwrap(); + crate::utils::write_line(&self.node, &raw_val)?; Ok(()) }, None => Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "val is none")), diff --git a/src/main.rs b/src/main.rs index f37ec73..a280b5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,7 +141,9 @@ fn main() -> std::io::Result<()> { for config in &configs { for local_config in &local_configs { if config.node == local_config.node && local_config.value != None && config.value != local_config.value && local_config.writeable() { - need_change.push(config.clone()); + let mut config_new = local_config.clone(); + config_new.value = config.value.clone(); + need_change.push(config_new); } } } @@ -149,7 +151,9 @@ fn main() -> std::io::Result<()> { for config in need_change { if let Some(val) = &config.value { println!("apply: {} = {}", config.node, val); - config.apply().expect(&format!("ERROR: apply {} failed", config.node)) + if let Err(e) = config.apply() { + println!("ERROR: apply {} failed {}", config.node, e) + } } } } diff --git a/src/utils.rs b/src/utils.rs index 65556f8..6527708 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -12,7 +12,8 @@ pub fn read_line(path: &str) -> std::io::Result { pub fn write_line(path: &str, val: &str) -> std::io::Result<()> { let mut input = File::create(path)?; - input.write_all(val.as_bytes()) + let val_line = format!("{}\n", val); + input.write_all(val_line.as_bytes()) } pub fn read_all_line(path: &str) -> std::io::Result {