]> git.pld-linux.org Git - packages/parted.git/blob - 0106-clean-the-disk-information-when-commands-fail-in-int.patch
- release 6 (by relup.sh)
[packages/parted.git] / 0106-clean-the-disk-information-when-commands-fail-in-int.patch
1 From 5a61f15b7003cba73e6517ac22204bafd9a3cb8e Mon Sep 17 00:00:00 2001
2 From: Wang Dong <dongdwdw@linux.vnet.ibm.com>
3 Date: Fri, 23 Dec 2016 06:53:38 +0100
4 Subject: [PATCH 106/106] clean the disk information when commands fail in
5  interactive mode.
6
7 parted always reads disk information to memory before any
8 operations. The disk that user operates is actually
9 a copy of real one in memory. When the information in memory
10 is changed, it will commit the memory to device to update the
11 disk information.
12
13 Once the disk information is read, parted will never re-read it
14 again unless another device is loaded or the device is re-read.
15 Above work has been done in commit 7eac058 (parted: don't reload
16 partition table on every command)
17
18 Each command of parted always commits the memory when it succeeds.
19 Then the disk information on device and in memory are the same.
20 But when it fails, they might be different. User will be confused
21 by this, and sometimes get undesired result with the contaminated
22 memory. This memory should be cleaned if some command fails.
23 Then the command followed will re-read the disk.
24
25 Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com>
26 Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
27 ---
28  parted/parted.c | 14 ++++++++++----
29  parted/ui.c     |  8 +++++++-
30  2 files changed, 17 insertions(+), 5 deletions(-)
31
32 diff --git a/parted/parted.c b/parted/parted.c
33 index 4bb7911..59ad59e 100644
34 --- a/parted/parted.c
35 +++ b/parted/parted.c
36 @@ -1390,8 +1390,12 @@ _rescue_add_partition (PedPartition* part)
37                  default: break;
38          }
39  
40 -        ped_partition_set_system (part, fs_type);
41 -        ped_disk_commit (part->disk);
42 +        if (!ped_partition_set_system (part, fs_type))
43 +                return 0;
44 +
45 +        if (!ped_disk_commit (part->disk))
46 +                return 0;
47 +
48          return 1;
49  }
50  
51 @@ -1601,8 +1605,10 @@ do_rm (PedDevice** dev, PedDisk** diskp)
52          if (!_partition_warn_busy (part))
53                  goto error;
54  
55 -        ped_disk_delete_partition (*diskp, part);
56 -        ped_disk_commit (*diskp);
57 +        if (!ped_disk_delete_partition (*diskp, part))
58 +                goto error;
59 +        if (!ped_disk_commit (*diskp))
60 +                goto error;
61  
62          if ((*dev)->type != PED_DEVICE_FILE)
63                  disk_is_modified = 1;
64 diff --git a/parted/ui.c b/parted/ui.c
65 index 5d76c20..af0539c 100644
66 --- a/parted/ui.c
67 +++ b/parted/ui.c
68 @@ -1612,8 +1612,14 @@ interactive_mode (PedDevice** dev, PedDisk** disk, Command* cmd_list[])
69                          cmd = command_get (commands, word);
70                          free (word);
71                          if (cmd) {
72 -                                if (!command_run (cmd, dev, disk))
73 +                                if (!command_run (cmd, dev, disk)) {
74                                          command_line_flush ();
75 +
76 +                                        if (*disk) {
77 +                                                ped_disk_destroy (*disk);
78 +                                                *disk = 0;
79 +                                        }
80 +                                }
81                          } else
82                                  print_commands_help ();
83                  }
84 -- 
85 2.20.1
86
This page took 0.073809 seconds and 3 git commands to generate.