Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wait for password-command to exit #699

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ New features:
- restore: The restore algorithm has been improved and should now be faster for remote repositories.
- restore: Files are now allocated just before being first processed. This allows easier resumed restores.
- New option: `no-require-git` for backup - if enabled, a git repository is not required to apply `git-ignore` rule.
- fix: wait for password-command to successfully exit, allowing to input something into the command, and read password from stdout.
24 changes: 18 additions & 6 deletions crates/rustic_core/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::{
fs::File,
io::{BufRead, BufReader},
path::PathBuf,
process::Command,
process::{Command, Stdio},
};

use bytes::Bytes;
use derive_more::Add;
use log::{debug, info};
use log::{debug, error, info};

use nom::{
branch::alt,
Expand Down Expand Up @@ -106,7 +106,7 @@ pub struct RepositoryOptions {
)]
pub password_file: Option<PathBuf>,

/// Command to read the password from
/// Command to read the password from. Password is read from stdout
#[cfg_attr(feature = "clap", clap(
long,
global = true,
Expand Down Expand Up @@ -267,10 +267,22 @@ impl<P> Repository<P> {
.map_err(RepositoryErrorKind::FromNomError)?
.1;
debug!("commands: {commands:?}");
let Ok(output) = Command::new(commands[0]).args(&commands[1..]).output() else {
return Err(
RepositoryErrorKind::PasswordCommandParsingFailed.into());
let command = Command::new(commands[0])
.args(&commands[1..])
.stdout(Stdio::piped())
.spawn()?;
let Ok(output) = command.wait_with_output() else {
return Err(RepositoryErrorKind::PasswordCommandParsingFailed.into());
};
if !output.status.success() {
#[allow(clippy::option_if_let_else)]
let s = match output.status.code() {
Some(c) => format!("exited with status code {c}"),
None => "was terminated".into(),
};
error!("password-command {s}");
return Err(RepositoryErrorKind::ReadingPasswordFromCommandFailed.into());
}

let mut pwd = BufReader::new(&*output.stdout);
Ok(Some(match read_password_from_reader(&mut pwd) {
Expand Down
Loading