Check for attributes being available before querying them
authorEmmanuele Bassi <ebassi@gnome.org>
Sat, 4 Mar 2023 00:02:52 +0000 (00:02 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Sat, 4 Mar 2023 15:28:53 +0000 (15:28 +0000)
GLib 2.75 started checking if a GFileInfo was created with the attribute
we're querying, instead of failing silently and leaving us in an
inconsistent state.

Turns out that GtkFileChooserWidget, GtkFileSystemModel, and GtkPathBar
trip the newly introduced check.

gtk/gtkfilechooserwidget.c
gtk/gtkfilesystemmodel.c
gtk/gtkpathbar.c

index 70276967e577457ee684c2231ce17448b845396c..0c29b31076227bef7309fe936404013cfc6cf464 100644 (file)
@@ -3549,9 +3549,12 @@ show_and_select_files (GtkFileChooserWidget *impl,
 
       if (!g_file_info_get_attribute_boolean (info, "filechooser::visible"))
         {
+          gboolean has_is_hidden = g_file_info_has_attribute (info, "standard::is-hidden");
+          gboolean has_is_backup = g_file_info_has_attribute (info, "standard::is-backup");
+
           if (!enabled_hidden &&
-              (g_file_info_get_is_hidden (info) ||
-               g_file_info_get_is_backup (info)))
+              ((has_is_hidden && g_file_info_get_is_hidden (info)) ||
+               (has_is_backup && g_file_info_get_is_backup (info))))
             {
               set_show_hidden (impl, TRUE);
               enabled_hidden = TRUE;
index 9f4a5fafa9310a87e7e2f2b0ed20b6ba9e64a052..d37237f1c773add5b4b02715ceec87470444ee64 100644 (file)
@@ -209,13 +209,18 @@ node_should_be_visible (GtkFileSystemModel *model,
                         gboolean            filtered_out)
 {
   FileModelNode *node = get_node (model, id);
+  gboolean has_is_hidden;
+  gboolean has_is_backup;
   gboolean result;
 
   if (node->info == NULL)
     return FALSE;
 
+  has_is_hidden = g_file_info_has_attribute (node->info, "standard::is-hidden");
+  has_is_backup = g_file_info_has_attribute (node->info, "standard::is-backup");
   if (!model->show_hidden &&
-      (g_file_info_get_is_hidden (node->info) || g_file_info_get_is_backup (node->info)))
+      ((has_is_hidden && g_file_info_get_is_hidden (node->info)) ||
+       (has_is_backup && g_file_info_get_is_backup (node->info))))
     return FALSE;
 
   if (_gtk_file_info_consider_as_directory (node->info))
@@ -941,7 +946,7 @@ _gtk_file_system_model_set_filter_folders (GtkFileSystemModel *model,
  * @model: the model
  *
  * Gets the cancellable used by the @model. This is the cancellable used
- * internally by the @model that will be cancelled when @model is 
+ * internally by the @model that will be cancelled when @model is
  * disposed. So you can use it for operations that should be cancelled
  * when the model goes away.
  *
@@ -1005,7 +1010,7 @@ _gtk_file_system_model_update_files (GtkFileSystemModel *model,
  * _gtk_file_system_model_set_filter:
  * @mode: a `GtkFileSystemModel`
  * @filter: (nullable): %NULL or filter to use
- * 
+ *
  * Sets a filter to be used for deciding if a row should be visible or not.
  * Whether this filter applies to directories can be toggled with
  * _gtk_file_system_model_set_filter_folders().
@@ -1028,7 +1033,7 @@ _gtk_file_system_model_set_filter (GtkFileSystemModel      *model,
  * @file: the file to add
  * @attributes: attributes to query before adding the file
  *
- * This is a convenience function that calls g_file_query_info_async() on 
+ * This is a convenience function that calls g_file_query_info_async() on
  * the given file, and when successful, adds it to the model.
  * Upon failure, the @file is discarded.
  **/
index 1e3f1c669aa1f7d310817ace6e187b7bde8edaab..a19985732e21573af7c0644cb4076702bf574a07 100644 (file)
@@ -218,7 +218,7 @@ gtk_path_bar_init (GtkPathBar *path_bar)
       desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
       if (desktop != NULL)
         path_bar->desktop_file = g_file_new_for_path (desktop);
-      else 
+      else
         path_bar->desktop_file = NULL;
     }
   else
@@ -306,7 +306,7 @@ update_visibility_up_to_next_root (GtkPathBar *path_bar,
 {
   gboolean fake_root_found = FALSE;
   GList *l;
-  
+
   for (l = start_from_button; l; l = l->next)
     {
       GtkWidget *button = BUTTON_DATA (l->data)->button;
@@ -776,6 +776,7 @@ gtk_path_bar_get_info_callback (GObject      *source,
   GFileInfo *info;
   ButtonData *button_data;
   const char *display_name;
+  gboolean has_is_hidden, has_is_backup;
   gboolean is_hidden;
 
   info = g_file_query_info_finish (file, result, NULL);
@@ -794,7 +795,10 @@ gtk_path_bar_get_info_callback (GObject      *source,
   file_info->cancellable = NULL;
 
   display_name = g_file_info_get_display_name (info);
-  is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
+  has_is_hidden = g_file_info_has_attribute (info, "standard::is-hidden");
+  has_is_backup = g_file_info_has_attribute (info, "standard::is-backup");
+  is_hidden = (has_is_hidden && g_file_info_get_is_hidden (info)) ||
+    (has_is_backup && g_file_info_get_is_backup (info));
 
   button_data = make_directory_button (file_info->path_bar, display_name,
                                        file_info->file,
@@ -879,7 +883,7 @@ _gtk_path_bar_set_file (GtkPathBar *path_bar,
 /**
  * _gtk_path_bar_up:
  * @path_bar: a `GtkPathBar`
- * 
+ *
  * If the selected button in the pathbar is not the furthest button “up” (in the
  * root direction), act as if the user clicked on the next button up.
  **/
@@ -906,7 +910,7 @@ _gtk_path_bar_up (GtkPathBar *path_bar)
 /**
  * _gtk_path_bar_down:
  * @path_bar: a `GtkPathBar`
- * 
+ *
  * If the selected button in the pathbar is not the furthest button “down” (in the
  * leaf direction), act as if the user clicked on the next button down.
  **/