Skip to content

Commit

Permalink
removes v1-v2 upgrade message when no rooster file is available
Browse files Browse the repository at this point in the history
  • Loading branch information
conradkleinespel committed Jan 11, 2016
1 parent 98db827 commit 1b4a5a9
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,28 @@ fn execute_command_from_filename(matches: &getopts::Matches, command: &Command,
let mut input: Vec<u8> = Vec::new();
try!(file.read_to_end(&mut input).map_err(|_| 1));

// Try to open the file as is.
let mut store = match password::v2::PasswordStore::from_input(master_password.clone(), SafeVec::new(input.clone())) {
Ok(store) => store,
Err(_) => {
// If we can't open the file, we may need to upgrade its format first.
match password::upgrade(master_password.clone(), SafeVec::new(input.clone())) {
Ok(store) => store,
Err(_) => {
// If we can't upgrade its format either, we show a helpful
// error message.
println_err!("I could not upgrade the Rooster file. This could be because:");
println_err!("- you explicitly told Rooster not to open the file,");
println_err!("- your version of Rooster is outdated,");
println_err!("- your Rooster file is corrupted,");
println_err!("- your master password is wrong.");
println_err!("Try upgrading to the latest version of Rooster.");
return Err(1);
// If the password file is empty (ie new), we'll make a new, empty store.
let mut store = if input.len() == 0 {
try!(password::v2::PasswordStore::new(master_password.clone()).map_err(|_| 1))
} else {
// Try to open the file as is.
match password::v2::PasswordStore::from_input(master_password.clone(), SafeVec::new(input.clone())) {
Ok(store) => store,
Err(_) => {
// If we can't open the file, we may need to upgrade its format first.
match password::upgrade(master_password.clone(), SafeVec::new(input.clone())) {
Ok(store) => store,
Err(_) => {
// If we can't upgrade its format either, we show a helpful
// error message.
println_err!("I could not upgrade the Rooster file. This could be because:");
println_err!("- you explicitly told Rooster not to open the file,");
println_err!("- your version of Rooster is outdated,");
println_err!("- your Rooster file is corrupted,");
println_err!("- your master password is wrong.");
println_err!("Try upgrading to the latest version of Rooster.");
return Err(1);
}
}
}
}
Expand Down

0 comments on commit 1b4a5a9

Please sign in to comment.