From d558abfe5125483f73d0718e9d24a6961f175c72 Mon Sep 17 00:00:00 2001 From: Morten Welinder Date: Mon, 8 Mar 2004 16:16:26 +0000 Subject: [PATCH] If we fail, leave widget unchanged. Explicitly verify final directory. 2004-03-08 Morten Welinder * gtk/gtkpathbar.c (_gtk_path_bar_set_path): If we fail, leave widget unchanged. Explicitly verify final directory. --- ChangeLog | 3 +++ ChangeLog.pre-2-10 | 3 +++ ChangeLog.pre-2-4 | 3 +++ ChangeLog.pre-2-6 | 3 +++ ChangeLog.pre-2-8 | 3 +++ gtk/gtkpathbar.c | 54 +++++++++++++++++++++++++++++++++++----------- 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index d654fee3a8..329fbd0fed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2004-03-08 Morten Welinder + * gtk/gtkpathbar.c (_gtk_path_bar_set_path): If we fail, leave + widget unchanged. Explicitly verify final directory. + * gtk/gtkfilesystemunix.c (gtk_file_system_unix_create_folder, get_icon_type, filename_get_info): Protect errno. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index d654fee3a8..329fbd0fed 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,8 @@ 2004-03-08 Morten Welinder + * gtk/gtkpathbar.c (_gtk_path_bar_set_path): If we fail, leave + widget unchanged. Explicitly verify final directory. + * gtk/gtkfilesystemunix.c (gtk_file_system_unix_create_folder, get_icon_type, filename_get_info): Protect errno. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index d654fee3a8..329fbd0fed 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,5 +1,8 @@ 2004-03-08 Morten Welinder + * gtk/gtkpathbar.c (_gtk_path_bar_set_path): If we fail, leave + widget unchanged. Explicitly verify final directory. + * gtk/gtkfilesystemunix.c (gtk_file_system_unix_create_folder, get_icon_type, filename_get_info): Protect errno. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index d654fee3a8..329fbd0fed 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,5 +1,8 @@ 2004-03-08 Morten Welinder + * gtk/gtkpathbar.c (_gtk_path_bar_set_path): If we fail, leave + widget unchanged. Explicitly verify final directory. + * gtk/gtkfilesystemunix.c (gtk_file_system_unix_create_folder, get_icon_type, filename_get_info): Protect errno. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index d654fee3a8..329fbd0fed 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,8 @@ 2004-03-08 Morten Welinder + * gtk/gtkpathbar.c (_gtk_path_bar_set_path): If we fail, leave + widget unchanged. Explicitly verify final directory. + * gtk/gtkfilesystemunix.c (gtk_file_system_unix_create_folder, get_icon_type, filename_get_info): Protect errno. diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c index 671be4ea13..4a6d979e97 100644 --- a/gtk/gtkpathbar.c +++ b/gtk/gtkpathbar.c @@ -808,6 +808,7 @@ _gtk_path_bar_set_path (GtkPathBar *path_bar, GtkFilePath *path; gboolean first_directory = TRUE; gboolean result; + GList *new_buttons = NULL; g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE); g_return_val_if_fail (file_path != NULL, FALSE); @@ -817,7 +818,6 @@ _gtk_path_bar_set_path (GtkPathBar *path_bar, if (gtk_path_bar_check_parent_path (path_bar, file_path, path_bar->file_system)) return TRUE; - gtk_path_bar_clear_buttons (path_bar); path = gtk_file_path_copy (file_path); gtk_widget_push_composite_child (); @@ -831,6 +831,7 @@ _gtk_path_bar_set_path (GtkPathBar *path_bar, GtkFileFolder *file_folder; GtkFileInfo *file_info; gboolean valid; + GtkFileInfoType needed = GTK_FILE_INFO_DISPLAY_NAME; ButtonType button_type; valid = gtk_file_system_get_parent (path_bar->file_system, @@ -845,18 +846,23 @@ _gtk_path_bar_set_path (GtkPathBar *path_bar, break; } - if (parent_path) - file_folder = gtk_file_system_get_folder (path_bar->file_system, parent_path, - GTK_FILE_INFO_DISPLAY_NAME, NULL); - else - file_folder = gtk_file_system_get_folder (path_bar->file_system, path, - GTK_FILE_INFO_DISPLAY_NAME, NULL); + if (first_directory) + needed |= GTK_FILE_INFO_IS_FOLDER; + + file_folder = gtk_file_system_get_folder + (path_bar->file_system, + parent_path ? parent_path : path, + needed, + NULL); file_info = gtk_file_folder_get_info (file_folder, path, &err); - if (!file_info) + if (!file_info || (first_directory && !gtk_file_info_get_is_folder (file_info))) { result = FALSE; + g_propagate_error (error, err); + if (file_info) + gtk_file_info_free (file_info); g_object_unref (file_folder); gtk_file_path_free (parent_path); gtk_file_path_free (path); @@ -870,8 +876,7 @@ _gtk_path_bar_set_path (GtkPathBar *path_bar, gtk_file_path_free (path); g_object_unref (file_folder); - gtk_container_add (GTK_CONTAINER (path_bar), button); - path_bar->button_list = g_list_prepend (path_bar->button_list, button); + new_buttons = g_list_prepend (new_buttons, button); button_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "gtk-path-bar-button-type")); if (button_type != NORMAL_BUTTON) @@ -885,9 +890,34 @@ _gtk_path_bar_set_path (GtkPathBar *path_bar, first_directory = FALSE; } - gtk_widget_pop_composite_child (); + if (result) + { + GList *l; - path_bar->button_list = g_list_reverse (path_bar->button_list); + gtk_path_bar_clear_buttons (path_bar); + path_bar->button_list = g_list_reverse (new_buttons); + + for (l = path_bar->button_list; l; l = l->next) + { + GtkWidget *button = l->data; + gtk_container_add (GTK_CONTAINER (path_bar), button); + } + } + else + { + GList *l; + + for (l = new_buttons; l; l = l->next) + { + GtkWidget *button = l->data; + gtk_widget_destroy (button); + gtk_widget_unref (button); + } + + g_list_free (new_buttons); + } + + gtk_widget_pop_composite_child (); return result; }