mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-02 00:00:03 +03:00
fix reading keys from non-tty inputs
read_password_from_tty doesn't have a fallback if input is a pipe. This makes scripting and integration testing harder. Noticed while updating our nixos integration test. Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
This commit is contained in:
parent
3ab89de5fa
commit
9090bf3c36
@ -72,7 +72,13 @@ fn ask_for_key(sb: &bch_sb_handle) -> anyhow::Result<()> {
|
||||
|
||||
let bch_key_magic = BCH_KEY_MAGIC.as_bytes().read_u64::<LittleEndian>().unwrap();
|
||||
let crypt = sb.sb().crypt().unwrap();
|
||||
let pass = rpassword::read_password_from_tty(Some("Enter passphrase: "))?;
|
||||
let pass = if atty::is(atty::Stream::Stdin) {
|
||||
rpassword::read_password_from_tty(Some("Enter passphrase: "))?
|
||||
} else {
|
||||
let mut line = String::new();
|
||||
std::io::stdin().read_line(&mut line)?;
|
||||
line
|
||||
};
|
||||
let pass = std::ffi::CString::new(pass.trim_end())?; // bind to keep the CString alive
|
||||
let mut output: bch_key = unsafe {
|
||||
bcachefs::derive_passphrase(
|
||||
|
Loading…
Reference in New Issue
Block a user