GNU bug report logs - #43993
parted in script mode still needs "yes/no" as input in "are you sure" questions

Previous Next

Package: parted;

Reported by: Michael Kopp <kopp.michael <at> yahoo.de>

Date: Wed, 14 Oct 2020 20:25:02 UTC

Severity: normal

To reply to this bug, email your comments to 43993 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-parted <at> gnu.org:
bug#43993; Package parted. (Wed, 14 Oct 2020 20:25:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michael Kopp <kopp.michael <at> yahoo.de>:
New bug report received and forwarded. Copy sent to bug-parted <at> gnu.org. (Wed, 14 Oct 2020 20:25:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Michael Kopp <kopp.michael <at> yahoo.de>
To: bug-parted <at> gnu.org
Subject: parted in script mode still needs "yes/no" as input in "are you sure"
 questions
Date: Wed, 14 Oct 2020 20:55:45 +0200
Hi,

I wanted to use parted in a script and used the `--script` option.
Unfortunately, I wanted to do something risky (resizing the partition 
that is still mounted -- in my defense: It's only in a virtual machine), 
and then the script will not continue but die with

    Warning: partition /dev/sda2 is being used.  Are you sure
    you want to continue?

The program does not run through and the size is not changed.
Even using something like `yes | parted --script ...` does not fix the 
issue.

This does sound like kind of a bug to me.
I would propose to add something like an `--assume-yes` option, which 
will answer to the messages in some way to make the script continue (or 
only to yes/no questions?).

I took a look at the code, how one could add something like this but I'm 
not fluent in this kind of C programming.  The little thingy I could 
produce was the following patch.

What do you think about the behavior and the proposal?

Cheers,
Michael


```
diff --git a/parted/parted.c b/parted/parted.c
index dbd38d0..58b0621 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -115,6 +115,7 @@ static struct option const options[] = {
         {"list",        0, NULL, 'l'},
         {"machine",     0, NULL, 'm'},
         {"script",      0, NULL, 's'},
+        {"assume-yes",  0, NULL, 'y'},
         {"version",     0, NULL, 'v'},
         {"align",       required_argument, NULL, 'a'},
         {"-pretend-input-tty", 0, NULL, PRETEND_INPUT_TTY},
@@ -126,12 +127,14 @@ static const char *const options_help [][2] = {
         {"list",        N_("lists partition layout on all block 
devices")},
         {"machine",     N_("displays machine parseable output")},
         {"script",      N_("never prompts for user intervention")},
+        {"assume-yes",  N_("Assume yes to all answers (useful in script 
mode)")},
         {"version",     N_("displays the version")},
         {"align=[none|cyl|min|opt]", N_("alignment for new partitions")},
         {NULL,          NULL}
 };

 int     opt_script_mode = 0;
+int     opt_assume_yes = 0;
 int     pretend_input_tty = 0;
 int     opt_machine_mode = 0;
 int     disk_is_modified = 0;
@@ -225,6 +228,14 @@ _partition_warn_busy (PedPartition* part)

         if (ped_partition_is_busy (part)) {
                 path = ped_partition_get_path (part);
+                if (opt_assume_yes)
+                {
+                        printf(_("Partition %s is being used, but "
+                                 "assume-yes mode is on, so we will go 
ahead."),
+                                 path);
+                        free (path);
+                        return 1;
+                }
                 if (ped_exception_throw (
                             PED_EXCEPTION_WARNING,
                             PED_EXCEPTION_YES_NO,
```

-- 
Michael Kopp <kopp.michael <at> yahoo.de>




Information forwarded to bug-parted <at> gnu.org:
bug#43993; Package parted. (Wed, 14 Oct 2020 20:33:02 GMT) Full text and rfc822 format available.

Message #8 received at 43993 <at> debbugs.gnu.org (full text, mbox):

From: "Brian C. Lane" <bcl <at> redhat.com>
To: Michael Kopp <kopp.michael <at> yahoo.de>
Cc: 43993 <at> debbugs.gnu.org
Subject: Re: bug#43993: parted in script mode still needs "yes/no" as input
 in "are you sure" questions
Date: Wed, 14 Oct 2020 13:32:07 -0700
On Wed, Oct 14, 2020 at 08:55:45PM +0200, Michael Kopp via Bug reports for the GNU Parted disk partition editor wrote:
> Hi,
> 
> I wanted to use parted in a script and used the `--script` option.
> Unfortunately, I wanted to do something risky (resizing the partition 
> that is still mounted -- in my defense: It's only in a virtual machine), 
> and then the script will not continue but die with
> 
>      Warning: partition /dev/sda2 is being used.  Are you sure
>      you want to continue?

I'm reluctant to add something like this because of the potential for
data loss when things go wrong. The script mode defaults to 'safe' for
all of the prompts like this to avoid unexpected surprises.

Brian

-- 
Brian C. Lane (PST8PDT) - weldr.io - lorax - parted - pykickstart





This bug report was last modified 3 years and 194 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.