Skip to content

Commit 16040da

Browse files
author
replydev
committed
Use dirs dependency
1 parent dbc3aaa commit 16040da

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ version = "0.0.9"
44
authors = ["replydev <replydev@protonmail.com>"]
55
edition = "2018"
66

7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8-
97
[dependencies]
108
serde_json = "1.0.60"
119
serde = { version = "1", features = ["derive"] }
12-
directories = "3.0.1"
10+
dirs = "3.0.1"
1311
rpassword = "5.0.0"
1412
sodiumoxide = "0.2.6"
1513
base64 = "0.13.0"

src/database_loader.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn edit_element(mut id: usize, secret: &str,issuer: &str,label: &str) -> Res
142142
let mut elements: Vec<OTPElement>;
143143
match read_from_file(){
144144
Ok(result) => elements = result,
145-
Err(e) => return Err(String::from("Cannot decrypt existing database"))
145+
Err(_e) => return Err(String::from("Cannot decrypt existing database"))
146146
}
147147

148148

@@ -169,7 +169,8 @@ pub fn edit_element(mut id: usize, secret: &str,issuer: &str,label: &str) -> Res
169169
}
170170

171171
pub fn export_database() -> Result<String, String> {
172-
let exported_path = utils::get_home_folder() + "/exported.cotp";
172+
let mut exported_path = utils::get_home_folder().to_str().unwrap().to_string();
173+
exported_path.push_str("/exported.cotp");
173174
let mut file = File::create(&exported_path).expect("Cannot create file");
174175
let mut encrypted_contents = read_to_string(&get_db_path()).unwrap();
175176
let contents = cryptograpy::decrypt_string(&mut encrypted_contents, &cryptograpy::prompt_for_passwords("Password: "));

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::env;
22
mod database_loader;
3-
extern crate directories;
43
mod utils;
54
mod argument_functions;
65
mod otp_helper;
@@ -36,6 +35,7 @@ fn main() {
3635
return;
3736
}
3837
}
38+
println!("{}",utils::get_db_path().to_str().unwrap());
3939
let args: Vec<String> = env::args().collect();
4040
if !args_parser(args){
4141
utils::create_db_if_needed();

src/utils.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
use directories::BaseDirs;
21
use std::fs::{File};
32
use std::io::prelude::*;
4-
use std::path::Path;
3+
use std::path::{Path,PathBuf};
4+
use dirs::home_dir;
55
use super::database_loader;
66

77
#[cfg(debug_assertions)]
8-
pub fn get_db_path() -> String{
9-
String::from("db.cotp")
8+
pub fn get_db_path() -> PathBuf{
9+
PathBuf::from("db.cotp")
1010
}
1111

1212
#[cfg(not(debug_assertions))]
13-
pub fn get_db_path() -> String{
14-
let mut home_dir = get_home_folder();
15-
home_dir.push_str("/.cotp");
16-
home_dir.push_str("/db.cotp");
17-
home_dir
13+
pub fn get_db_path() -> PathBuf{
14+
let mut home_dir = get_home_folder().to_str().unwrap().to_string();
15+
home_dir.push_str("/.cotp/db.cotp");
16+
PathBuf::from(home_dir)
1817
}
1918

20-
pub fn get_home_folder() -> String {
21-
let base_dirs = BaseDirs::new().unwrap();
22-
let home = base_dirs.home_dir().to_str().unwrap();
23-
home.to_string()
19+
pub fn get_home_folder() -> PathBuf {
20+
home_dir().unwrap()
2421
}
2522

2623
pub fn create_db_if_needed(){

0 commit comments

Comments
 (0)