[mio] 去除获取目录失败的unwrap
This commit is contained in:
@@ -175,11 +175,19 @@ pub fn get_device_id() -> String {
|
|||||||
if let Some(id) = common::identifier::get_unique_identifier() {
|
if let Some(id) = common::identifier::get_unique_identifier() {
|
||||||
id
|
id
|
||||||
} else {
|
} 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()) {
|
if let Ok(id) = std::fs::read_to_string(path_buf.as_path()) {
|
||||||
id
|
id
|
||||||
} else {
|
} else {
|
||||||
let id = uuid::Uuid::new_v4().to_string();
|
|
||||||
let _ = std::fs::write(path_buf, &id);
|
let _ = std::fs::write(path_buf, &id);
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -18,10 +18,8 @@ mod console_out;
|
|||||||
mod root_check;
|
mod root_check;
|
||||||
|
|
||||||
pub fn app_home() -> io::Result<PathBuf> {
|
pub fn app_home() -> io::Result<PathBuf> {
|
||||||
let path = std::env::current_exe()
|
let path = std::env::current_exe()?
|
||||||
.expect("current_exe error")
|
.parent().ok_or(io::Error::new(io::ErrorKind::Other,"current_exe parent error"))?
|
||||||
.parent()
|
|
||||||
.expect("current_exe parent error")
|
|
||||||
.join("env");
|
.join("env");
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
std::fs::create_dir_all(&path)?;
|
std::fs::create_dir_all(&path)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user