Added a check to return an empty string when attempting to read a file that doesn't exist
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
901ef7818d
commit
f32becf5f5
@ -1,4 +1,4 @@
|
||||
use std::{fs::{File, create_dir_all}, io::{Read, Write}, path::PathBuf};
|
||||
use std::{fs::{File, create_dir_all}, io::{Read, Write}, path::{Path, PathBuf}};
|
||||
|
||||
use hyper_tls::HttpsConnector;
|
||||
use hyper::{Body, Client, body, client::HttpConnector};
|
||||
@ -32,6 +32,7 @@ fn write_to_file(d: &str, p: &str) {
|
||||
}
|
||||
|
||||
fn read_from_file(p: &str) -> String {
|
||||
if !Path::new(p).exists() { return "".to_string(); }
|
||||
let mut d = String::new();
|
||||
let mut ifile = File::open(p).expect("Cannot open file.");
|
||||
ifile.read_to_string(&mut d).expect("Cannot read file.");
|
||||
|
Loading…
Reference in New Issue
Block a user