Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Remove some unwraps from parity/helpers (#3364)
Browse files Browse the repository at this point in the history
* Fixing no stdin

* Removing unwrap when reading passwords
  • Loading branch information
tomusdrw authored and gavofyork committed Nov 11, 2016
1 parent 80606cd commit 4bf75d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions parity/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,18 @@ pub fn execute_upgrades(
/// Prompts user asking for password.
pub fn password_prompt() -> Result<String, String> {
use rpassword::read_password;
const STDIN_ERROR: &'static str = "Unable to ask for password on non-interactive terminal.";

println!("Please note that password is NOT RECOVERABLE.");
print!("Type password: ");
flush_stdout();

let password = read_password().unwrap();
let password = try!(read_password().map_err(|_| STDIN_ERROR.to_owned()));

print!("Repeat password: ");
flush_stdout();

let password_repeat = read_password().unwrap();
let password_repeat = try!(read_password().map_err(|_| STDIN_ERROR.to_owned()));

if password != password_repeat {
return Err("Passwords do not match!".into());
Expand All @@ -314,7 +315,7 @@ pub fn passwords_from_files(files: Vec<String>) -> Result<Vec<String>, String> {
let file = try!(File::open(filename).map_err(|_| format!("{} Unable to read password file. Ensure it exists and permissions are correct.", filename)));
let reader = BufReader::new(&file);
let lines = reader.lines()
.map(|l| l.unwrap())
.filter_map(|l| l.ok())
.collect::<Vec<String>>();
Ok(lines)
}).collect::<Result<Vec<Vec<String>>, String>>();
Expand Down

0 comments on commit 4bf75d6

Please sign in to comment.