diff options
author | Bradford Hovinen <hovinen@ximian.com> | 2001-06-19 18:31:18 +0000 |
---|---|---|
committer | Bradford Hovinen (Gdict maintainer) <hovinen@src.gnome.org> | 2001-06-19 18:31:18 +0000 |
commit | 172e5c0939a4ce17089eda9e679bcea9f07db7b7 (patch) | |
tree | 4ae5fd610ecad9182031e6ecc1432aab6b0fc1bf /archiver/archive.c | |
parent | aa7315ed93eac0cf8ad48fa5a5c64cffd573c1e5 (diff) | |
download | gnome-control-center-172e5c0939a4ce17089eda9e679bcea9f07db7b7.tar.gz |
Free the location path as we walk down it. (create_backends_list):
2001-06-19 Bradford Hovinen <hovinen@ximian.com>
* archive.c (archive_set_current_location): Free the location path
as we walk down it.
(create_backends_list): Implement
(merge_backend_lists): Implement
(archive_set_current_location): Call above functions
(create_backends_list): Get rid of dummy first element
(archive_set_current_location): Don't use backends->next when
calling rollback_backends_to
* location.c (run_backend_proc): Remember to close the writing end
(location_store): Change g_error to g_critical
(run_backend_proc): Don't getenv PATH
(run_backend_proc): Make sure to close other end of pipe in child
process
2001-06-18 Bradford Hovinen <hovinen@ximian.com>
* location.c (location_store): Use GString API
* config-log.c (slave_data_cb): Don't use == to test IO conditions
Diffstat (limited to 'archiver/archive.c')
-rw-r--r-- | archiver/archive.c | 108 |
1 files changed, 91 insertions, 17 deletions
diff --git a/archiver/archive.c b/archiver/archive.c index 5ce505836..746e342a7 100644 --- a/archiver/archive.c +++ b/archiver/archive.c @@ -426,6 +426,92 @@ add_location_cb (Location *location, gchar *backend_id, GList *backends) return 0; } +/* Create a list of backends that differ between location1 and the common + * parent of location1 and location2 */ + +static GList * +create_backends_list (Location *location1, Location *location2) +{ + GList *location_path, *backends, *tmp; + + location_path = location_find_path_from_common_parent + (location1, location2); + + /* Skip the first entry -- it is the common parent */ + tmp = location_path; + location_path = location_path->next; + g_list_free_1 (tmp); + + backends = g_list_append (NULL, NULL); + + while (location_path != NULL) { + if (location_path->data != NULL) { + location_foreach_backend + (LOCATION (location_path->data), + (LocationBackendCB) add_location_cb, + backends); + } + + tmp = location_path; + location_path = location_path->next; + g_list_free_1 (tmp); + } + + tmp = backends; + backends = backends->next; + g_list_free_1 (tmp); + + return backends; +} + +/* Merge two backend lists, eliminating duplicates */ + +GList * +merge_backend_lists (GList *backends1, GList *backends2) +{ + GList *head = NULL, *tail = NULL, *tmp; + int res; + + backends1 = g_list_sort (backends1, (GCompareFunc) strcmp); + backends2 = g_list_sort (backends2, (GCompareFunc) strcmp); + + while (backends1 && backends2) { + res = strcmp (backends1->data, backends2->data); + + if (res < 0) { + if (tail != NULL) tail->next = backends1; + else head = backends1; + tail = backends1; + backends1 = backends1->next; + } + else if (res > 0) { + if (tail != NULL) tail->next = backends2; + else head = backends2; + tail = backends2; + backends2 = backends2->next; + } else { + if (tail != NULL) tail->next = backends1; + else head = backends1; + tail = backends1; + backends1 = backends1->next; + tmp = backends2; + backends2 = backends2->next; + g_list_free_1 (tmp); + } + } + + if (backends1 != NULL) { + if (tail != NULL) tail->next = backends1; + else head = backends1; + } + else { + if (tail != NULL) tail->next = backends2; + else head = backends2; + } + + return head; +} + /** * archive_set_current_location: * @archive: object @@ -438,7 +524,7 @@ add_location_cb (Location *location, gchar *backend_id, GList *backends) void archive_set_current_location (Archive *archive, Location *location) { - GList *location_path, *backends; + GList *backends1, *backends2, *backends, *tmp; Location *old_location = archive_get_current_location (archive); g_return_if_fail (archive != NULL); @@ -448,23 +534,11 @@ archive_set_current_location (Archive *archive, Location *location) archive_set_current_location_id (archive, location_get_id (location)); - location_path = location_find_path_from_common_parent - (location, old_location); - - backends = g_list_append (NULL, NULL); - - while (location_path != NULL) { - if (location_path->data != NULL) { - location_foreach_backend - (LOCATION (location_path->data), - (LocationBackendCB) add_location_cb, - backends); - } - - location_path = location_path->next; - } + backends1 = create_backends_list (location, old_location); + backends2 = create_backends_list (old_location, location); + backends = merge_backend_lists (backends1, backends2); - location_rollback_backends_to (location, NULL, backends->next, TRUE); + location_rollback_backends_to (location, NULL, backends, TRUE); g_list_free (backends); } |