diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/tests/test_disk.c | 45 | ||||
| -rw-r--r-- | lib/utils_disk.c | 21 | ||||
| -rw-r--r-- | lib/utils_disk.h | 2 |
3 files changed, 66 insertions, 2 deletions
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c index ac9db005..fcde4f85 100644 --- a/lib/tests/test_disk.c +++ b/lib/tests/test_disk.c | |||
| @@ -36,14 +36,15 @@ main (int argc, char **argv) | |||
| 36 | struct name_list *dummy_mountlist = NULL; | 36 | struct name_list *dummy_mountlist = NULL; |
| 37 | struct name_list *temp_name; | 37 | struct name_list *temp_name; |
| 38 | struct parameter_list *paths = NULL; | 38 | struct parameter_list *paths = NULL; |
| 39 | struct parameter_list *p; | 39 | struct parameter_list *p, *prev, *last; |
| 40 | 40 | ||
| 41 | struct mount_entry *dummy_mount_list; | 41 | struct mount_entry *dummy_mount_list; |
| 42 | struct mount_entry *me; | 42 | struct mount_entry *me; |
| 43 | struct mount_entry **mtail = &dummy_mount_list; | 43 | struct mount_entry **mtail = &dummy_mount_list; |
| 44 | int cflags = REG_NOSUB | REG_EXTENDED; | 44 | int cflags = REG_NOSUB | REG_EXTENDED; |
| 45 | int found = 0, count = 0; | ||
| 45 | 46 | ||
| 46 | plan_tests(29); | 47 | plan_tests(33); |
| 47 | 48 | ||
| 48 | ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); | 49 | ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); |
| 49 | np_add_name(&exclude_filesystem, "/var/log"); | 50 | np_add_name(&exclude_filesystem, "/var/log"); |
| @@ -160,6 +161,46 @@ main (int argc, char **argv) | |||
| 160 | } | 161 | } |
| 161 | } | 162 | } |
| 162 | 163 | ||
| 164 | /* test deleting first element in paths */ | ||
| 165 | paths = np_del_parameter(paths, NULL); | ||
| 166 | for (p = paths; p; p = p->name_next) { | ||
| 167 | if (! strcmp(p->name, "/home/groups")) | ||
| 168 | found = 1; | ||
| 169 | } | ||
| 170 | ok(found == 0, "first element successfully deleted"); | ||
| 171 | found = 0; | ||
| 172 | |||
| 173 | p=paths; | ||
| 174 | while (p) { | ||
| 175 | if (! strcmp(p->name, "/tmp")) | ||
| 176 | p = np_del_parameter(p, prev); | ||
| 177 | else { | ||
| 178 | prev = p; | ||
| 179 | p = p->name_next; | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | for (p = paths; p; p = p->name_next) { | ||
| 184 | if (! strcmp(p->name, "/tmp")) | ||
| 185 | found = 1; | ||
| 186 | if (p->name_next) | ||
| 187 | prev = p; | ||
| 188 | else | ||
| 189 | last = p; | ||
| 190 | } | ||
| 191 | ok(found == 0, "/tmp element successfully deleted"); | ||
| 192 | |||
| 193 | p = np_del_parameter(last, prev); | ||
| 194 | for (p = paths; p; p = p->name_next) { | ||
| 195 | if (! strcmp(p->name, "/home")) | ||
| 196 | found = 1; | ||
| 197 | last = p; | ||
| 198 | count++; | ||
| 199 | } | ||
| 200 | ok(found == 0, "last (/home) element successfully deleted"); | ||
| 201 | ok(count == 2, "two elements remaining"); | ||
| 202 | |||
| 203 | |||
| 163 | return exit_status(); | 204 | return exit_status(); |
| 164 | } | 205 | } |
| 165 | 206 | ||
diff --git a/lib/utils_disk.c b/lib/utils_disk.c index 96f5a306..3f9c8a9a 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c | |||
| @@ -74,6 +74,26 @@ np_add_parameter(struct parameter_list **list, const char *name) | |||
| 74 | return new_path; | 74 | return new_path; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | /* Delete a given parameter from list and return pointer to next element*/ | ||
| 78 | struct parameter_list * | ||
| 79 | np_del_parameter(struct parameter_list *item, struct parameter_list *prev) | ||
| 80 | { | ||
| 81 | struct parameter_list *next; | ||
| 82 | if (item->name_next) | ||
| 83 | next = item->name_next; | ||
| 84 | else | ||
| 85 | next = NULL; | ||
| 86 | |||
| 87 | |||
| 88 | free(item); | ||
| 89 | if (prev) | ||
| 90 | prev->name_next = next; | ||
| 91 | |||
| 92 | return next; | ||
| 93 | |||
| 94 | } | ||
| 95 | |||
| 96 | |||
| 77 | /* returns a pointer to the struct found in the list */ | 97 | /* returns a pointer to the struct found in the list */ |
| 78 | struct parameter_list * | 98 | struct parameter_list * |
| 79 | np_find_parameter(struct parameter_list *list, const char *name) | 99 | np_find_parameter(struct parameter_list *list, const char *name) |
| @@ -166,3 +186,4 @@ np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) | |||
| 166 | return false; | 186 | return false; |
| 167 | } | 187 | } |
| 168 | } | 188 | } |
| 189 | |||
diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 6263339f..f99b9050 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h | |||
| @@ -31,6 +31,8 @@ int np_find_name (struct name_list *list, const char *name); | |||
| 31 | int np_seen_name (struct name_list *list, const char *name); | 31 | int np_seen_name (struct name_list *list, const char *name); |
| 32 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); | 32 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); |
| 33 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); | 33 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); |
| 34 | struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); | ||
| 35 | |||
| 34 | int search_parameter_list (struct parameter_list *list, const char *name); | 36 | int search_parameter_list (struct parameter_list *list, const char *name); |
| 35 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact); | 37 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact); |
| 36 | int np_regex_match_mount_entry (struct mount_entry* me, regex_t* re); | 38 | int np_regex_match_mount_entry (struct mount_entry* me, regex_t* re); |
