[parted-devel] [PATCH 4/6] parted: make _partition_warn_busy actually a warning instead of an error

Phillip Susi psusi at ubuntu.com
Fri Jan 18 04:56:37 UTC 2013


This function was throwing a PED_EXCEPTION_ERROR with only the
PED_EXCEPTION_CANCEL option.  Converted to a PED_EXCEPTION_WARNING
with the option to continue anyhow.
---
 parted/parted.c                                 |   19 +++++++++++--------
 tests/t1101-busy-partition.sh                   |    2 +-
 tests/t9041-undetected-in-use-16th-partition.sh |    4 ++--
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/parted/parted.c b/parted/parted.c
index 28c874b..b65c1cb 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -222,14 +222,17 @@ _partition_warn_busy (PedPartition* part)
 
         if (ped_partition_is_busy (part)) {
                 path = ped_partition_get_path (part);
-                ped_exception_throw (
-                        PED_EXCEPTION_ERROR,
-                        PED_EXCEPTION_CANCEL,
-                        _("Partition %s is being used. You must unmount it "
-                          "before you modify it with Parted."),
-                        path);
-                free (path);
-                return 0;
+                if (ped_exception_throw (
+                            PED_EXCEPTION_WARNING,
+                            PED_EXCEPTION_YES_NO,
+                            _("Partition %s is being used. Are you sure you " \
+                              "want to continue?"),
+                            path) != PED_EXCEPTION_YES)
+                {
+                        free (path);
+                        return 0;
+                }
+		free (path);
         }
         return 1;
 }
diff --git a/tests/t1101-busy-partition.sh b/tests/t1101-busy-partition.sh
index 81ccdb8..d0db709 100755
--- a/tests/t1101-busy-partition.sh
+++ b/tests/t1101-busy-partition.sh
@@ -29,7 +29,7 @@ scsi_debug_setup_ dev_size_mb=80 > dev-name ||
 dev=$(cat dev-name)
 
 cat <<EOF > exp-error || framework_failure
-Error: Partition ${dev}2 is being used. You must unmount it before you modify it with Parted.
+Warning: Partition ${dev}2 is being used. Are you sure you want to continue?
 EOF
 
 parted -s "$dev" mklabel msdos > out 2>&1 || fail=1
diff --git a/tests/t9041-undetected-in-use-16th-partition.sh b/tests/t9041-undetected-in-use-16th-partition.sh
index 2c4390d..f4c75b9 100644
--- a/tests/t9041-undetected-in-use-16th-partition.sh
+++ b/tests/t9041-undetected-in-use-16th-partition.sh
@@ -87,8 +87,8 @@ for part_dev in $partitions; do
   # Removal of mounted partition must fail.
   parted -s $scsi_dev rm $n > out 2>&1 && fail=1
 
-  echo "Error: Partition $part_dev is being used." \
-	  'You must unmount it before you modify it with Parted.' \
+  echo "Warning: Partition $part_dev is being used." \
+          'Are you sure you want to continue?' \
     > exp-error || framework_failure_
 
   # expect error
-- 
1.7.10.4




More information about the parted-devel mailing list