* [pbs-devel] [PATCH proxmox-backup 2/2] backup_manager: use confirmation helper in wipe-disk command
@ 2024-06-19 10:15 Gabriel Goller
2024-07-02 8:51 ` Gabriel Goller
2024-07-03 9:20 ` [pbs-devel] applied: " Wolfgang Bumiller
0 siblings, 2 replies; 3+ messages in thread
From: Gabriel Goller @ 2024-06-19 10:15 UTC (permalink / raw)
To: pbs-devel
Use `Confirmation` helper in the wipe-disk command prompt.
Improves: 887d83cb (cli: add interactive confirmation for block device wipe, 2023-11-29)
Cc: Markus Frank <m.frank@proxmox.com>
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
src/bin/proxmox_backup_manager/disk.rs | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/bin/proxmox_backup_manager/disk.rs b/src/bin/proxmox_backup_manager/disk.rs
index 9c55a989..d0fdfc6f 100644
--- a/src/bin/proxmox_backup_manager/disk.rs
+++ b/src/bin/proxmox_backup_manager/disk.rs
@@ -3,7 +3,7 @@ use serde_json::Value;
use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
use proxmox_schema::api;
-use std::io::{IsTerminal, Write};
+use std::io::IsTerminal;
use pbs_api_types::{
ZfsCompressionType, ZfsRaidLevel, BLOCKDEVICE_DISK_AND_PARTITION_NAME_SCHEMA,
@@ -155,17 +155,16 @@ async fn wipe_disk(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<
// If we're on a TTY, query the user
if std::io::stdin().is_terminal() {
- println!("You are about to wipe block device {}.", param["disk"]);
- print!("Are you sure you want to continue? (y/N): ");
- let _ = std::io::stdout().flush();
- use std::io::{BufRead, BufReader};
- let mut line = String::new();
- match BufReader::new(std::io::stdin()).read_line(&mut line) {
- Ok(_) => match line.trim() {
- "y" | "Y" => (), // continue
- _ => bail!("Aborting."),
- },
- Err(err) => bail!("Failed to read line - {err}."),
+ let confirmation = Confirmation::query_with_default(
+ format!(
+ "You are about to wipe block device {}. Are you sure you want to continue?",
+ param["disk"]
+ )
+ .as_str(),
+ Confirmation::No,
+ )?;
+ if confirmation.is_no() {
+ bail!("Aborting.");
}
}
--
2.43.0
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup 2/2] backup_manager: use confirmation helper in wipe-disk command
2024-06-19 10:15 [pbs-devel] [PATCH proxmox-backup 2/2] backup_manager: use confirmation helper in wipe-disk command Gabriel Goller
@ 2024-07-02 8:51 ` Gabriel Goller
2024-07-03 9:20 ` [pbs-devel] applied: " Wolfgang Bumiller
1 sibling, 0 replies; 3+ messages in thread
From: Gabriel Goller @ 2024-07-02 8:51 UTC (permalink / raw)
To: Proxmox Backup Server development discussion
Note: This is a single patch, the '2/2' in the header is my mistake!
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pbs-devel] applied: [PATCH proxmox-backup 2/2] backup_manager: use confirmation helper in wipe-disk command
2024-06-19 10:15 [pbs-devel] [PATCH proxmox-backup 2/2] backup_manager: use confirmation helper in wipe-disk command Gabriel Goller
2024-07-02 8:51 ` Gabriel Goller
@ 2024-07-03 9:20 ` Wolfgang Bumiller
1 sibling, 0 replies; 3+ messages in thread
From: Wolfgang Bumiller @ 2024-07-03 9:20 UTC (permalink / raw)
To: Gabriel Goller; +Cc: pbs-devel
applied, but restored the newline that was droppped with the patch
On Wed, Jun 19, 2024 at 12:15:44PM GMT, Gabriel Goller wrote:
> Use `Confirmation` helper in the wipe-disk command prompt.
>
> Improves: 887d83cb (cli: add interactive confirmation for block device wipe, 2023-11-29)
> Cc: Markus Frank <m.frank@proxmox.com>
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> ---
> src/bin/proxmox_backup_manager/disk.rs | 23 +++++++++++------------
> 1 file changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/src/bin/proxmox_backup_manager/disk.rs b/src/bin/proxmox_backup_manager/disk.rs
> index 9c55a989..d0fdfc6f 100644
> --- a/src/bin/proxmox_backup_manager/disk.rs
> +++ b/src/bin/proxmox_backup_manager/disk.rs
> @@ -3,7 +3,7 @@ use serde_json::Value;
>
> use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
> use proxmox_schema::api;
> -use std::io::{IsTerminal, Write};
> +use std::io::IsTerminal;
>
> use pbs_api_types::{
> ZfsCompressionType, ZfsRaidLevel, BLOCKDEVICE_DISK_AND_PARTITION_NAME_SCHEMA,
> @@ -155,17 +155,16 @@ async fn wipe_disk(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<
>
> // If we're on a TTY, query the user
> if std::io::stdin().is_terminal() {
> - println!("You are about to wipe block device {}.", param["disk"]);
> - print!("Are you sure you want to continue? (y/N): ");
> - let _ = std::io::stdout().flush();
> - use std::io::{BufRead, BufReader};
> - let mut line = String::new();
> - match BufReader::new(std::io::stdin()).read_line(&mut line) {
> - Ok(_) => match line.trim() {
> - "y" | "Y" => (), // continue
> - _ => bail!("Aborting."),
> - },
> - Err(err) => bail!("Failed to read line - {err}."),
> + let confirmation = Confirmation::query_with_default(
> + format!(
> + "You are about to wipe block device {}. Are you sure you want to continue?",
> + param["disk"]
> + )
> + .as_str(),
> + Confirmation::No,
> + )?;
> + if confirmation.is_no() {
> + bail!("Aborting.");
> }
> }
>
> --
> 2.43.0
>
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
>
>
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-03 9:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-19 10:15 [pbs-devel] [PATCH proxmox-backup 2/2] backup_manager: use confirmation helper in wipe-disk command Gabriel Goller
2024-07-02 8:51 ` Gabriel Goller
2024-07-03 9:20 ` [pbs-devel] applied: " Wolfgang Bumiller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox