diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-09-19 15:04:18 +0200 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2020-09-20 10:50:26 -0700 |
commit | d5c357e4564318577cf7e36d0f29b566f61dc825 (patch) | |
tree | 3d2d95abef64a342e757509bab29e7482398f370 /src/commands.rs | |
parent | 57a177e2f946390559a1f17787c5a15d23ac3393 (diff) | |
download | nitrocli-d5c357e4564318577cf7e36d0f29b566f61dc825.tar.gz nitrocli-d5c357e4564318577cf7e36d0f29b566f61dc825.tar.bz2 |
Add the --progress option to the fill command
The fill command starts a background operation on a Nitrokey Storage
device that fills the SD card with random data. This patch adds a new
option, --progress, to the fill command that checks if a fill operation
is already running on the device and shows its progress.
Diffstat (limited to 'src/commands.rs')
-rw-r--r-- | src/commands.rs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/commands.rs b/src/commands.rs index ced976c..9685050 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -471,19 +471,30 @@ pub fn list(ctx: &mut Context<'_>, no_connect: bool) -> anyhow::Result<()> { } /// Fill the SD card with random data -pub fn fill(ctx: &mut Context<'_>) -> anyhow::Result<()> { +pub fn fill(ctx: &mut Context<'_>, attach: bool) -> anyhow::Result<()> { with_storage_device(ctx, |ctx, mut device| { - let pin_entry = pinentry::PinEntry::from(args::PinType::Admin, &device)?; + let mut initial_progress = 0; + if attach { + let status = device + .get_operation_status() + .context("Failed to query operation status")?; + match status { + nitrokey::OperationStatus::Ongoing(progress) => initial_progress = progress, + nitrokey::OperationStatus::Idle => anyhow::bail!("No fill operation in progress"), + } + } else { + let pin_entry = pinentry::PinEntry::from(args::PinType::Admin, &device)?; - // Similar to reset, we want the user to re-enter the admin PIN even if is cached to avoid - // accidental data loss. - pinentry::clear(&pin_entry).context("Failed to clear cached secret")?; + // Similar to reset, we want the user to re-enter the admin PIN + // even if is cached to avoid accidental data loss. + pinentry::clear(&pin_entry).context("Failed to clear cached secret")?; - try_with_pin(ctx, &pin_entry, |pin| { - device.fill_sd_card(&pin).context("Failed to fill SD card") - })?; + try_with_pin(ctx, &pin_entry, |pin| { + device.fill_sd_card(&pin).context("Failed to fill SD card") + })?; + } - let mut progress_bar = output::ProgressBar::new(); + let mut progress_bar = output::ProgressBar::new(initial_progress); progress_bar.draw(ctx)?; while !progress_bar.is_finished() { |