[parted-devel] [PATCH 05/10] Ensure "blank" cmd-line before ped_exception_throw

Joel Granados Moreno jgranado at redhat.com
Tue Jun 9 11:35:02 UTC 2009


When ped_exception_throw requires input from the user and there are
leftover strings in the command line, there is an "invalid token" error
from parted.  This happens because the ped_exception expects some input
that is, most likely, different from the leftover string(s).  To address
this, one must make sure that all the argument strings are parsed before
invoking any exception that requires input.

* parted/parted.c (do_mklabel): Put the command_line_get_disk_type call
  before the disk checks (_disk_warn_loss will call ped_exception_throw)
* tests/t0000-basic.sh : The output needs not to include the error
  message.
---
 parted/parted.c      |    9 +++++----
 tests/t0000-basic.sh |    4 +---
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/parted/parted.c b/parted/parted.c
index ac1b176..5a4822d 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -595,13 +595,17 @@ static int
 do_mklabel (PedDevice** dev)
 {
         PedDisk*                disk;
-        const PedDiskType*      type = ped_disk_probe (*dev);
+        const PedDiskType*      type = NULL;
 
         ped_exception_fetch_all ();
         disk = ped_disk_new (*dev);
         if (!disk) ped_exception_catch ();
         ped_exception_leave_all ();
 
+        if (!command_line_get_disk_type (_("New disk label type?"),
+                    &type))
+                goto error;
+
         if (disk) {
                 if (!_disk_warn_busy (disk))
                         goto error_destroy_disk;
@@ -611,9 +615,6 @@ do_mklabel (PedDevice** dev)
                 ped_disk_destroy (disk);
         }
 
-        if (!command_line_get_disk_type (_("New disk label type?"), &type))
-                goto error;
-
         disk = ped_disk_new_fresh (*dev, type);
         if (!disk)
                 goto error;
diff --git a/tests/t0000-basic.sh b/tests/t0000-basic.sh
index 4d7f2ee..6b6b07e 100755
--- a/tests/t0000-basic.sh
+++ b/tests/t0000-basic.sh
@@ -64,7 +64,7 @@ test_expect_success \
     'check its "interactive" output' \
     'compare out exp 1>&2'
 
-test_expect_success 'create interactive input' 'printf "y\n\n" > in'
+test_expect_success 'create interactive input' 'printf "y\n" > in'
 
 # Now that there's a label, rerunning the same command is interactive.
 test_expect_success \
@@ -84,9 +84,7 @@ fail=0
 cat <<EOF >> exp || fail=1
 Warning: The existing disk label on DEVICE will be destroyed and all\
  data on this disk will be lost. Do you want to continue?
-parted: invalid token: msdos
 Yes/No? y
-New disk label type?  [msdos]?
 EOF
 test_expect_success \
     'create expected output file' \
-- 
1.6.0.6




More information about the parted-devel mailing list