diff options
author | Wang Dong <dongdwdw@linux.vnet.ibm.com> | 2016-12-23 06:53:38 +0100 |
---|---|---|
committer | Brian C. Lane <bcl@redhat.com> | 2017-05-01 15:03:31 -0700 |
commit | 5a61f15b7003cba73e6517ac22204bafd9a3cb8e (patch) | |
tree | 44e9d2a5e1c2b5fd2ac6e86f66c550255c12effd /parted | |
parent | af150f6764a08eae4b4cf448c392259c067a1523 (diff) | |
download | parted-5a61f15b7003cba73e6517ac22204bafd9a3cb8e.tar.gz |
clean the disk information when commands fail in interactive mode.
parted always reads disk information to memory before any
operations. The disk that user operates is actually
a copy of real one in memory. When the information in memory
is changed, it will commit the memory to device to update the
disk information.
Once the disk information is read, parted will never re-read it
again unless another device is loaded or the device is re-read.
Above work has been done in commit 7eac058 (parted: don't reload
partition table on every command)
Each command of parted always commits the memory when it succeeds.
Then the disk information on device and in memory are the same.
But when it fails, they might be different. User will be confused
by this, and sometimes get undesired result with the contaminated
memory. This memory should be cleaned if some command fails.
Then the command followed will re-read the disk.
Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com>
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Diffstat (limited to 'parted')
-rw-r--r-- | parted/parted.c | 14 | ||||
-rw-r--r-- | parted/ui.c | 8 |
2 files changed, 17 insertions, 5 deletions
diff --git a/parted/parted.c b/parted/parted.c index 4bb7911..59ad59e 100644 --- a/parted/parted.c +++ b/parted/parted.c @@ -1390,8 +1390,12 @@ _rescue_add_partition (PedPartition* part) default: break; } - ped_partition_set_system (part, fs_type); - ped_disk_commit (part->disk); + if (!ped_partition_set_system (part, fs_type)) + return 0; + + if (!ped_disk_commit (part->disk)) + return 0; + return 1; } @@ -1601,8 +1605,10 @@ do_rm (PedDevice** dev, PedDisk** diskp) if (!_partition_warn_busy (part)) goto error; - ped_disk_delete_partition (*diskp, part); - ped_disk_commit (*diskp); + if (!ped_disk_delete_partition (*diskp, part)) + goto error; + if (!ped_disk_commit (*diskp)) + goto error; if ((*dev)->type != PED_DEVICE_FILE) disk_is_modified = 1; diff --git a/parted/ui.c b/parted/ui.c index 5d76c20..af0539c 100644 --- a/parted/ui.c +++ b/parted/ui.c @@ -1612,8 +1612,14 @@ interactive_mode (PedDevice** dev, PedDisk** disk, Command* cmd_list[]) cmd = command_get (commands, word); free (word); if (cmd) { - if (!command_run (cmd, dev, disk)) + if (!command_run (cmd, dev, disk)) { command_line_flush (); + + if (*disk) { + ped_disk_destroy (*disk); + *disk = 0; + } + } } else print_commands_help (); } |