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
This commit is contained in:
Bradford Hovinen 2001-06-19 18:31:18 +00:00 committed by Bradford Hovinen (Gdict maintainer)
parent aa7315ed93
commit 172e5c0939
5 changed files with 139 additions and 48 deletions

View file

@ -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);
backends1 = create_backends_list (location, old_location);
backends2 = create_backends_list (old_location, location);
backends = merge_backend_lists (backends1, backends2);
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;
}
location_rollback_backends_to (location, NULL, backends->next, TRUE);
location_rollback_backends_to (location, NULL, backends, TRUE);
g_list_free (backends);
}