OSDN Git Service

parted-ui: ensure cmd-line buffer is empty before ped_exception_throw
authorJoel Granados Moreno <jgranado@redhat.com>
Wed, 10 Jun 2009 17:05:50 +0000 (19:05 +0200)
committerJim Meyering <meyering@redhat.com>
Wed, 10 Jun 2009 19:23:25 +0000 (21:23 +0200)
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): Call command_line_get_disk_type call
before the disk checks (_disk_warn_loss will call ped_exception_throw).
* tests/t0000-basic.sh: Adjust, now that the output need not include
the error message.

parted/parted.c
tests/t0000-basic.sh

index ac1b176..e6364bf 100644 (file)
@@ -1,6 +1,6 @@
 /*
     parted - a frontend to libparted
-    Copyright (C) 1999-2003, 2005-2008 Free Software Foundation, Inc.
+    Copyright (C) 1999-2003, 2005-2009 Free Software Foundation, Inc.
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -595,13 +595,16 @@ 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 +614,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;
index 4d7f2ee..6b6b07e 100755 (executable)
@@ -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' \