From e2dd62ad6bc7143665fbedb2b808274a6921b7aa Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Wed, 4 Sep 2024 09:35:23 +0000 Subject: [PATCH] storae db --- src/main.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8f6f99b..73f9fc2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,11 +5,13 @@ use std::io; use std::path::Path; -const STORAGE_PATH: &str = "storage"; +const STORAGE_FOLDER: &str = "storage"; +const STORAGE_PATH: &str = "storage/db.mps"; // TODO: concat from STORAGE_FOLDER + #[derive(Parser)] -#[command(name = "mps", version = "0.0.1", about = "MyPasswordStorage: Tool for storing your passwords locally with synchronization with git.")] +#[command(name = "mps", version = "0.0.1", about = "MyPasswordStorage: Tool for storing your passwords locally with git synchronization")] struct Cli { #[command(subcommand)] command: Option, @@ -30,7 +32,7 @@ enum Commands { } fn is_inited() -> bool { - let path = Path::new(STORAGE_PATH); + let path = Path::new(STORAGE_FOLDER); return path.exists(); } @@ -38,13 +40,23 @@ fn init() -> io::Result<()> { if is_inited() { return Err(io::Error::new(io::ErrorKind::AlreadyExists, "Reinitialization attempted")); } - match fs::create_dir(STORAGE_PATH) { + match fs::create_dir(STORAGE_FOLDER) { Ok(_) => { - println!("Initialization complete"); - return Ok(()); + println!("Create folder for storage"); // TODO: make it only in debug mode }, - Err(_) => return Err(io::Error::new(io::ErrorKind::Other, "Bad initialization")), + Err(_) => return Err(io::Error::new(io::ErrorKind::Other, "Can`t create storage folder")), } + + match fs::File::create(STORAGE_PATH) { + Ok(_) => { + println!("Storage db created"); + }, + Err(_) => { + return Err(io::Error::new(io::ErrorKind::Other, "Can`t create mps.db")); // TODO: better error, not just Other + } + } + + Ok(()) } fn main() -> io::Result<()> { @@ -73,7 +85,6 @@ fn main() -> io::Result<()> { } else { println!("login, not implemented yet") } - println!("Will be here init or list if storage inited"); } } Ok(())