ietf

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 43c503faf37aa19ca68b9f1616d6e57f4bc6bca8
parent 992cbfe46511010351eb576dea44313e3c529c8a
Author: cy6erlion <dev@merely.tech>
Date:   Tue, 29 Dec 2020 18:05:17 +0200

check if storage directory has been created

Diffstat:
Msrc/lib.rs | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -100,6 +100,7 @@ fn index_exists() -> Result<bool, ()> { if Path::new(&path).exists() { return Ok(true); } else { + init_storage_sir().unwrap(); return Ok(false); } } else { @@ -121,9 +122,32 @@ fn is_rfc_downloaded(sn: u32) -> Result<bool, ()> { if Path::new(&path).exists() { return Ok(true); } else { + init_storage_sir().unwrap(); return Ok(false); } } else { panic!("Could not find home directory"); } } + +// Check and create storage directory +fn init_storage_sir() -> std::io::Result<()> { + if let Some(home_path) = dirs_next::home_dir() { + let path = if cfg!(unix) || cfg!(macos) { + format!("{}/rfc", home_path.to_str().unwrap()) + } else if cfg!(windows) { + format!("{}\\rfc", home_path.to_str().unwrap()) + } else { + panic!("Unsupported OS"); + }; + + if Path::new(&path).exists() { + return Ok(()); + } else { + std::fs::create_dir(path)?; + return Ok(()); + } + } else { + panic!("Could not find home directory"); + } +}