From 8b49c440f81b8812c40f25eff217956dec7557cf Mon Sep 17 00:00:00 2001 From: kwaroran Date: Tue, 1 Aug 2023 12:13:44 +0900 Subject: [PATCH] [feat] check auth path --- src-tauri/src/main.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index f37db11a..93fb2a6b 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -90,7 +90,7 @@ fn check_auth(fpath: String, auth: String) -> bool{ println!("File {} is not a file", path.display()); return false; } - + // check file size let size = std::fs::metadata(&fpath).unwrap().len(); @@ -102,14 +102,23 @@ fn check_auth(fpath: String, auth: String) -> bool{ - // read file - let got_auth = std::fs::read_to_string(&path).expect("Something went wrong reading the file"); + // read file, return false when error + let got_auth = std::fs::read_to_string(&path); - // check auth - if got_auth != auth { + // check read error + if got_auth.is_err() { + println!("Error reading file {}", path.display()); return false; } - return true; + else{ + // check auth + if got_auth.unwrap() != auth { + println!("Auth does not match"); + return false; + } + println!("Auth matches"); + return true; + } }