[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#43993: parted in script mode still needs "yes/no" as input in "are y
From: |
Michael Kopp |
Subject: |
bug#43993: parted in script mode still needs "yes/no" as input in "are you sure" questions |
Date: |
Wed, 14 Oct 2020 20:55:45 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 |
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@yahoo.de>
- bug#43993: parted in script mode still needs "yes/no" as input in "are you sure" questions,
Michael Kopp <=