diff --git a/src/storage.rs b/src/storage.rs index a03b0bd..31735fe 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -143,19 +143,12 @@ impl Storage { } pub fn init(passphrase: String) -> io::Result<()> { - // TODO: revrite all logic - // Check if the folder exists and is a directory - //if path.exists() && path.is_dir() { - // Err(io::Error::new(io::ErrorKind::NotFound, "Folder does not exist")) - //} - //fs::File::create(&*STORAGE_PATH)?; - //let st = Storage::new(passphrase); - //st.dump()?; - //println!("Storage db created."); - //println!("Initialization complete."); - //println!(""); - //println!("Now it's required to add folder `{}` under git manually.", &*STORAGE_FOLDER); - //println!("Don't worry it's going to be encrypted."); + Storage::check_installed()?; + let db_path = Storage::get_db_path()?; + fs::File::create(db_path)?; + let st = Storage::new(passphrase); + st.dump()?; + println!("Storage db created"); Ok(()) } @@ -169,10 +162,14 @@ impl Storage { format!("{} does not exist or not a dir", Storage::get_storage_path()?) )); } - + let git_path = storage_path.join(".git"); + if !git_path.exists() || !git_path.is_dir() { + return Err(io::Error::new( + io::ErrorKind::NotFound, + format!("{} not under git", Storage::get_storage_path()?) + )); + } Ok(()) - - // TODO check git } pub fn is_inited() -> io::Result {