From cc717a4060014397c1d1a6e821ca09bb4afa543f Mon Sep 17 00:00:00 2001 From: lubeilin <1791778603@qq.com> Date: Sat, 2 Mar 2024 11:57:00 +0800 Subject: [PATCH] =?UTF-8?q?[mio]=20=E5=8E=BB=E9=99=A4=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E5=A4=B1=E8=B4=A5=E7=9A=84unwrap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt-cli/src/config/mod.rs | 12 ++++++++++-- vnt-cli/src/main.rs | 6 ++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/vnt-cli/src/config/mod.rs b/vnt-cli/src/config/mod.rs index 2d8d3f0..8b4d9f0 100644 --- a/vnt-cli/src/config/mod.rs +++ b/vnt-cli/src/config/mod.rs @@ -175,11 +175,19 @@ pub fn get_device_id() -> String { if let Some(id) = common::identifier::get_unique_identifier() { id } else { - let path_buf = crate::app_home().unwrap().join("device-id"); + let id = uuid::Uuid::new_v4().to_string(); + let path_buf = match crate::app_home() { + Ok(path_buf) => { + path_buf.join("device-id") + } + Err(e) => { + log::warn!("{:?}",e); + return id; + } + }; if let Ok(id) = std::fs::read_to_string(path_buf.as_path()) { id } else { - let id = uuid::Uuid::new_v4().to_string(); let _ = std::fs::write(path_buf, &id); id } diff --git a/vnt-cli/src/main.rs b/vnt-cli/src/main.rs index e69507f..923832b 100644 --- a/vnt-cli/src/main.rs +++ b/vnt-cli/src/main.rs @@ -18,10 +18,8 @@ mod console_out; mod root_check; pub fn app_home() -> io::Result { - let path = std::env::current_exe() - .expect("current_exe error") - .parent() - .expect("current_exe parent error") + let path = std::env::current_exe()? + .parent().ok_or(io::Error::new(io::ErrorKind::Other,"current_exe parent error"))? .join("env"); if !path.exists() { std::fs::create_dir_all(&path)?;