Commit 97ce483d authored by Darin Adler's avatar Darin Adler

Fixed double free that was causing lots of nasty errors in the file

	* src/file-manager/fm-directory-view.c:
	(fm_directory_view_activate_entry):
	Fixed double free that was causing lots of nasty errors in
	the file manager.
	(fm_directory_view_load_uri):
	Made the old directory hang around a bit longer when loading
	a new uri.
	(display_selection_info):
	(fm_directory_view_send_selection_change):
	(display_selection_info_idle_cb):
	Fixed a storage leak and broke out the selection change into
	its own function instead of mixing it with the status line.
	Also made the selection actually use URIs instead of just
	names for the selected items.

	* libnautilus/nautilus-directory.h:
	libnautilus/nautilus-directory.c:
	(nautilus_file_get_uri):
	Added this function that gets a URI (rather than just a
	leaf name).

	* libnautilus/nautilus-directory.c:
	(nautilus_directory_finalize):
	(nautilus_self_check_directory):
	Added more self checks and fixed a bug where a metadata
	change would get lost if you delete the directory too soon
	after making the change.
parent fde66d2d
2000-01-20 Darin Adler <darin@eazel.com>
* src/file-manager/fm-directory-view.c:
(fm_directory_view_activate_entry):
Fixed double free that was causing lots of nasty errors in
the file manager.
(fm_directory_view_load_uri):
Made the old directory hang around a bit longer when loading
a new uri.
(display_selection_info):
(fm_directory_view_send_selection_change):
(display_selection_info_idle_cb):
Fixed a storage leak and broke out the selection change into
its own function instead of mixing it with the status line.
Also made the selection actually use URIs instead of just
names for the selected items.
* libnautilus/nautilus-directory.h:
libnautilus/nautilus-directory.c:
(nautilus_file_get_uri):
Added this function that gets a URI (rather than just a
leaf name).
* libnautilus/nautilus-directory.c:
(nautilus_directory_finalize):
(nautilus_self_check_directory):
Added more self checks and fixed a bug where a metadata
change would get lost if you delete the directory too soon
after making the change.
2000-01-20 John Sullivan <sullivan@eazel.com>
* libnautilus/gtkflist.c:
......
......@@ -126,6 +126,9 @@ nautilus_directory_finalize (GtkObject *object)
directory = NAUTILUS_DIRECTORY (object);
if (directory->details->write_metafile_idle_id != 0)
nautilus_directory_write_metafile (directory);
g_hash_table_remove (directory_objects, directory->details->uri_text);
/* Unref all the files. */
......@@ -152,7 +155,6 @@ nautilus_directory_finalize (GtkObject *object)
if (directory->details->alternate_metafile_uri != NULL)
gnome_vfs_uri_unref (directory->details->alternate_metafile_uri);
xmlFreeDoc (directory->details->metafile_tree);
nautilus_directory_remove_write_metafile_idle (directory);
g_free (directory->details);
......@@ -805,9 +807,29 @@ nautilus_file_get_name (NautilusFile *file)
{
g_return_val_if_fail (file != NULL, NULL);
g_assert (file->ref_count != 0);
g_assert (file->directory == NULL || NAUTILUS_IS_DIRECTORY (file->directory));
g_assert (file->info->name != NULL);
g_assert (file->info->name[0] != '\0');
return g_strdup (file->info->name);
}
char *
nautilus_file_get_uri (NautilusFile *file)
{
GnomeVFSURI *uri;
char *uri_text;
g_return_val_if_fail (file != NULL, NULL);
g_return_val_if_fail (file->directory != NULL, NULL);
uri = gnome_vfs_uri_append_path (file->directory->details->uri, file->info->name);
uri_text = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
gnome_vfs_uri_unref (uri);
return uri_text;
}
GnomeVFSFileInfo *
nautilus_file_get_info (NautilusFile *file)
{
......@@ -917,10 +939,19 @@ nautilus_self_check_directory (void)
file_count = 0;
nautilus_directory_get_files (directory, get_files_cb, &data_dummy);
nautilus_directory_set_metadata (directory, "TEST", "default", "value");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value");
gtk_object_unref (GTK_OBJECT (directory));
g_assert (g_hash_table_size (directory_objects) == 0);
directory = nautilus_directory_get ("file:///etc");
g_assert (g_hash_table_size (directory_objects) == 1);
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value");
/* nautilus_directory_escape_slashes */
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes (""), "");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes ("a"), "a");
......
......@@ -109,6 +109,7 @@ GnomeVFSFileInfo * nautilus_file_get_info (NautilusFile
void nautilus_file_ref (NautilusFile *file);
void nautilus_file_unref (NautilusFile *file);
char * nautilus_file_get_name (NautilusFile *file);
char * nautilus_file_get_uri (NautilusFile *file);
/* Utility functions for formatting file-related information.
* FIXME: Probably these should be moved to some appropriate place in libnautilus.
......
......@@ -126,6 +126,9 @@ nautilus_directory_finalize (GtkObject *object)
directory = NAUTILUS_DIRECTORY (object);
if (directory->details->write_metafile_idle_id != 0)
nautilus_directory_write_metafile (directory);
g_hash_table_remove (directory_objects, directory->details->uri_text);
/* Unref all the files. */
......@@ -152,7 +155,6 @@ nautilus_directory_finalize (GtkObject *object)
if (directory->details->alternate_metafile_uri != NULL)
gnome_vfs_uri_unref (directory->details->alternate_metafile_uri);
xmlFreeDoc (directory->details->metafile_tree);
nautilus_directory_remove_write_metafile_idle (directory);
g_free (directory->details);
......@@ -805,9 +807,29 @@ nautilus_file_get_name (NautilusFile *file)
{
g_return_val_if_fail (file != NULL, NULL);
g_assert (file->ref_count != 0);
g_assert (file->directory == NULL || NAUTILUS_IS_DIRECTORY (file->directory));
g_assert (file->info->name != NULL);
g_assert (file->info->name[0] != '\0');
return g_strdup (file->info->name);
}
char *
nautilus_file_get_uri (NautilusFile *file)
{
GnomeVFSURI *uri;
char *uri_text;
g_return_val_if_fail (file != NULL, NULL);
g_return_val_if_fail (file->directory != NULL, NULL);
uri = gnome_vfs_uri_append_path (file->directory->details->uri, file->info->name);
uri_text = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
gnome_vfs_uri_unref (uri);
return uri_text;
}
GnomeVFSFileInfo *
nautilus_file_get_info (NautilusFile *file)
{
......@@ -917,10 +939,19 @@ nautilus_self_check_directory (void)
file_count = 0;
nautilus_directory_get_files (directory, get_files_cb, &data_dummy);
nautilus_directory_set_metadata (directory, "TEST", "default", "value");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value");
gtk_object_unref (GTK_OBJECT (directory));
g_assert (g_hash_table_size (directory_objects) == 0);
directory = nautilus_directory_get ("file:///etc");
g_assert (g_hash_table_size (directory_objects) == 1);
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value");
/* nautilus_directory_escape_slashes */
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes (""), "");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes ("a"), "a");
......
......@@ -109,6 +109,7 @@ GnomeVFSFileInfo * nautilus_file_get_info (NautilusFile
void nautilus_file_ref (NautilusFile *file);
void nautilus_file_unref (NautilusFile *file);
char * nautilus_file_get_name (NautilusFile *file);
char * nautilus_file_get_uri (NautilusFile *file);
/* Utility functions for formatting file-related information.
* FIXME: Probably these should be moved to some appropriate place in libnautilus.
......
......@@ -126,6 +126,9 @@ nautilus_directory_finalize (GtkObject *object)
directory = NAUTILUS_DIRECTORY (object);
if (directory->details->write_metafile_idle_id != 0)
nautilus_directory_write_metafile (directory);
g_hash_table_remove (directory_objects, directory->details->uri_text);
/* Unref all the files. */
......@@ -152,7 +155,6 @@ nautilus_directory_finalize (GtkObject *object)
if (directory->details->alternate_metafile_uri != NULL)
gnome_vfs_uri_unref (directory->details->alternate_metafile_uri);
xmlFreeDoc (directory->details->metafile_tree);
nautilus_directory_remove_write_metafile_idle (directory);
g_free (directory->details);
......@@ -805,9 +807,29 @@ nautilus_file_get_name (NautilusFile *file)
{
g_return_val_if_fail (file != NULL, NULL);
g_assert (file->ref_count != 0);
g_assert (file->directory == NULL || NAUTILUS_IS_DIRECTORY (file->directory));
g_assert (file->info->name != NULL);
g_assert (file->info->name[0] != '\0');
return g_strdup (file->info->name);
}
char *
nautilus_file_get_uri (NautilusFile *file)
{
GnomeVFSURI *uri;
char *uri_text;
g_return_val_if_fail (file != NULL, NULL);
g_return_val_if_fail (file->directory != NULL, NULL);
uri = gnome_vfs_uri_append_path (file->directory->details->uri, file->info->name);
uri_text = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
gnome_vfs_uri_unref (uri);
return uri_text;
}
GnomeVFSFileInfo *
nautilus_file_get_info (NautilusFile *file)
{
......@@ -917,10 +939,19 @@ nautilus_self_check_directory (void)
file_count = 0;
nautilus_directory_get_files (directory, get_files_cb, &data_dummy);
nautilus_directory_set_metadata (directory, "TEST", "default", "value");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value");
gtk_object_unref (GTK_OBJECT (directory));
g_assert (g_hash_table_size (directory_objects) == 0);
directory = nautilus_directory_get ("file:///etc");
g_assert (g_hash_table_size (directory_objects) == 1);
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value");
/* nautilus_directory_escape_slashes */
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes (""), "");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes ("a"), "a");
......
......@@ -109,6 +109,7 @@ GnomeVFSFileInfo * nautilus_file_get_info (NautilusFile
void nautilus_file_ref (NautilusFile *file);
void nautilus_file_unref (NautilusFile *file);
char * nautilus_file_get_name (NautilusFile *file);
char * nautilus_file_get_uri (NautilusFile *file);
/* Utility functions for formatting file-related information.
* FIXME: Probably these should be moved to some appropriate place in libnautilus.
......
......@@ -237,7 +237,6 @@ display_selection_info (FMDirectoryView *view)
NautilusFileList *p;
char *first_item_name;
Nautilus_StatusRequestInfo sri;
Nautilus_SelectionRequestInfo selri;
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
......@@ -246,22 +245,18 @@ display_selection_info (FMDirectoryView *view)
count = 0;
size = 0;
first_item_name = NULL;
memset(&selri, 0, sizeof(selri));
selri.selected_uris._buffer = g_alloca(g_list_length(selection) * sizeof(char *));
for (p = selection; p != NULL; p = p->next) {
NautilusFile *file;
char *fn;
file = p->data;
count++;
size += nautilus_file_get_info (file)->size;
fn = nautilus_file_get_name (file);
if (first_item_name == NULL)
first_item_name = fn;
selri.selected_uris._buffer[selri.selected_uris._length++] = fn;
first_item_name = nautilus_file_get_name (file);
}
g_list_free (selection);
memset(&sri, 0, sizeof(sri));
if (count == 0)
......@@ -294,8 +289,33 @@ display_selection_info (FMDirectoryView *view)
nautilus_view_frame_request_status_change
(NAUTILUS_VIEW_FRAME (view->details->view_frame), &sri);
}
static void
fm_directory_view_send_selection_change (FMDirectoryView *view)
{
Nautilus_SelectionRequestInfo request;
NautilusFileList *selection;
NautilusFileList *p;
int i;
memset (&request, 0, sizeof (request));
/* Collect a list of URIs. */
selection = fm_directory_view_get_selection (view);
request.selected_uris._buffer = g_alloca (g_list_length (selection) * sizeof (char *));
for (p = selection; p != NULL; p = p->next)
request.selected_uris._buffer[request.selected_uris._length++]
= nautilus_file_get_uri (p->data);
g_list_free (selection);
/* Send the selection change. */
nautilus_view_frame_request_selection_change
(NAUTILUS_VIEW_FRAME (view->details->view_frame), &selri);
(NAUTILUS_VIEW_FRAME (view->details->view_frame), &request);
/* Free the URIs. */
for (i = 0; i < request.selected_uris._length; i++)
g_free (request.selected_uris._buffer[i]);
}
......@@ -411,7 +431,10 @@ display_selection_info_idle_cb (gpointer data)
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (data), FALSE);
view = FM_DIRECTORY_VIEW (data);
display_selection_info (view);
fm_directory_view_send_selection_change (view);
view->details->display_selection_idle_id = 0;
return FALSE;
......@@ -659,7 +682,7 @@ fm_directory_view_activate_entry (FMDirectoryView *view, NautilusFile *file)
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
g_return_if_fail (file != NULL);
name = nautilus_file_get_info (file)->name;
name = nautilus_file_get_name (file);
new_uri = gnome_vfs_uri_append_path(view->details->uri, name);
g_free (name);
......@@ -695,6 +718,7 @@ fm_directory_view_load_uri (FMDirectoryView *view,
}; /* FIXME */
GnomeVFSResult result;
Nautilus_ProgressRequestInfo pri;
NautilusDirectory *old_model;
g_return_if_fail (view != NULL);
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
......@@ -702,8 +726,7 @@ fm_directory_view_load_uri (FMDirectoryView *view,
fm_directory_view_stop (view);
if (view->details->model != NULL)
gtk_object_unref (GTK_OBJECT (view->details->model));
old_model = view->details->model;
view->details->model = nautilus_directory_get (uri);
if (view->details->uri != NULL)
......@@ -717,6 +740,9 @@ fm_directory_view_load_uri (FMDirectoryView *view,
fm_directory_view_clear (view);
if (old_model != NULL)
gtk_object_unref (GTK_OBJECT (old_model));
memset(&pri, 0, sizeof(pri));
pri.type = Nautilus_PROGRESS_UNDERWAY;
pri.amount = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment