|
|
|
@ -39,35 +39,18 @@ fn init() -> io::Result<()> {
|
|
|
|
|
if is_inited() { |
|
|
|
|
return Err(io::Error::new(io::ErrorKind::AlreadyExists, "Reinitialization attempted")); |
|
|
|
|
} |
|
|
|
|
match fs::create_dir(STORAGE_FOLDER) { |
|
|
|
|
Ok(_) => { |
|
|
|
|
println!("Create folder for storage"); // TODO: make it only in debug mode
|
|
|
|
|
}, |
|
|
|
|
Err(_) => return Err(io::Error::new(io::ErrorKind::Other, "Can`t create storage folder")), |
|
|
|
|
} |
|
|
|
|
fs::create_dir(STORAGE_FOLDER)?; |
|
|
|
|
println!("Storage folder created"); |
|
|
|
|
|
|
|
|
|
match fs::File::create(STORAGE_PATH) { |
|
|
|
|
Ok(_) => { |
|
|
|
|
fs::File::create(STORAGE_PATH)?; |
|
|
|
|
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 add() -> io::Result<()> { |
|
|
|
|
let mut file = match fs::OpenOptions::new() |
|
|
|
|
let mut file = fs::OpenOptions::new() |
|
|
|
|
.write(true) |
|
|
|
|
.open(STORAGE_PATH) |
|
|
|
|
{ |
|
|
|
|
Ok(file) => file, |
|
|
|
|
Err(_) => { |
|
|
|
|
return Err(io::Error::new(io::ErrorKind::Other, "can`t open database")); // TODO: better error handling
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
.open(STORAGE_PATH)?; |
|
|
|
|
|
|
|
|
|
writeln!(file, "new item")?; |
|
|
|
|
Ok(()) |
|
|
|
|