summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2023-03-07 14:50:22 +0100
committerOndrej Holy <oholy@redhat.com>2023-03-17 14:22:54 +0100
commit5a2b7a64e717eb5657eff4d5a379b5547e95353b (patch)
tree86ca06a61f74581008a6351bbea9cfa1519f1b35
parent07a7fa138809ce2dfaeb7a2066c5161c5ec55a34 (diff)
downloadnautilus-5a2b7a64e717eb5657eff4d5a379b5547e95353b.tar.gz
Use generic helpers for obtaining file attributes
It is not guaranteed that all `GFileInfo` attributes are always set when requested. They used to be silently set to `NULL`, `FALSE`, or `0` earlier when they were not provided by their implementations. However, some of the helper functions now print critical errors when the attributes are not set by their implementations even though they were requested. See the https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3261 merge request for more details. So Nautilus now prints tons of critical errors when started. The unset attributes can be detected over the `g_file_info_has_attribute` function. But Nautilus doesn't care in most cases about the reason why the attribute is `NULL`, `FALSE`, or `0`. There are also more generic helper functions that don't print these critical errors. Let's use them for the attributes that may not always be set to get rid of those critical errors. I suppose that the `name`, `display_name`, `size`, `icon`, and `file_type` attributes don't need this special handling, although it is not clearly stated anywhere... Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2861
-rw-r--r--src/nautilus-directory-async.c15
-rw-r--r--src/nautilus-file.c22
-rw-r--r--src/nautilus-search-engine-recent.c9
-rw-r--r--src/nautilus-search-engine-simple.c8
4 files changed, 39 insertions, 15 deletions
diff --git a/src/nautilus-directory-async.c b/src/nautilus-directory-async.c
index 3e7f421e6..3abe01332 100644
--- a/src/nautilus-directory-async.c
+++ b/src/nautilus-directory-async.c
@@ -906,6 +906,7 @@ should_skip_file (NautilusDirectory *directory,
GFileInfo *info)
{
static gboolean show_hidden_files_changed_callback_installed = FALSE;
+ gboolean is_hidden;
/* Add the callback once for the life of our process */
if (!show_hidden_files_changed_callback_installed)
@@ -921,9 +922,11 @@ should_skip_file (NautilusDirectory *directory,
show_hidden_files_changed_callback (NULL);
}
- if (!show_hidden_files &&
- (g_file_info_get_is_hidden (info) ||
- g_file_info_get_is_backup (info)))
+ is_hidden = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) ||
+ g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
+ if (!show_hidden_files && is_hidden)
{
return TRUE;
}
@@ -1003,7 +1006,8 @@ dequeue_pending_idle_callback (gpointer callback_data)
dir_load_state->load_file_count += 1;
/* Add the MIME type to the set. */
- mimetype = g_file_info_get_content_type (file_info);
+ mimetype = g_file_info_get_attribute_string (file_info,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
if (mimetype != NULL)
{
istr_set_insert (dir_load_state->load_mime_list_hash,
@@ -3260,7 +3264,8 @@ mime_list_one (MimeListState *state,
return;
}
- mime_type = g_file_info_get_content_type (info);
+ mime_type = g_file_info_get_attribute_string (info,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
if (mime_type != NULL)
{
istr_set_insert (state->mime_list_hash, mime_type);
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index b340cfc73..76283e219 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -2478,6 +2478,7 @@ update_info_internal (NautilusFile *file,
const char *trash_orig_path;
const char *group, *owner, *owner_real;
gboolean free_owner, free_group;
+ const char *edit_name;
if (file->details->is_gone)
{
@@ -2506,9 +2507,11 @@ update_info_internal (NautilusFile *file,
}
file->details->got_file_info = TRUE;
+ edit_name = g_file_info_get_attribute_string (info,
+ G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
changed |= nautilus_file_set_display_name (file,
g_file_info_get_display_name (info),
- g_file_info_get_edit_name (info),
+ edit_name,
FALSE);
file_type = g_file_info_get_file_type (info);
@@ -2554,14 +2557,18 @@ update_info_internal (NautilusFile *file,
}
}
- is_symlink = g_file_info_get_is_symlink (info);
+ is_symlink = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
if (file->details->is_symlink != is_symlink)
{
changed = TRUE;
}
file->details->is_symlink = is_symlink;
- is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
+ is_hidden = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) ||
+ g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
if (file->details->is_hidden != is_hidden)
{
changed = TRUE;
@@ -2786,7 +2793,8 @@ update_info_internal (NautilusFile *file,
}
file->details->size = size;
- sort_order = g_file_info_get_sort_order (info);
+ sort_order = g_file_info_get_attribute_int32 (info,
+ G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
if (file->details->sort_order != sort_order)
{
changed = TRUE;
@@ -2845,7 +2853,8 @@ update_info_internal (NautilusFile *file,
file->details->thumbnailing_failed = thumbnailing_failed;
}
- symlink_name = g_file_info_get_symlink_target (info);
+ symlink_name = g_file_info_get_attribute_byte_string (info,
+ G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
if (g_strcmp0 (file->details->symlink_name, symlink_name) != 0)
{
changed = TRUE;
@@ -2853,7 +2862,8 @@ update_info_internal (NautilusFile *file,
file->details->symlink_name = g_strdup (symlink_name);
}
- mime_type = g_file_info_get_content_type (info);
+ mime_type = g_file_info_get_attribute_string (info,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
if (mime_type == NULL)
{
mime_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
diff --git a/src/nautilus-search-engine-recent.c b/src/nautilus-search-engine-recent.c
index a31b9d88f..288775f4c 100644
--- a/src/nautilus-search-engine-recent.c
+++ b/src/nautilus-search-engine-recent.c
@@ -171,8 +171,13 @@ is_file_valid_recursive (NautilusSearchEngineRecent *self,
if (!nautilus_query_get_show_hidden_files (self->query))
{
- if (!g_file_info_get_is_hidden (file_info) &&
- !g_file_info_get_is_backup (file_info))
+ gboolean is_hidden;
+
+ is_hidden = g_file_info_get_attribute_boolean (file_info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) ||
+ g_file_info_get_attribute_boolean (file_info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
+ if (!is_hidden)
{
g_autoptr (GFile) parent = g_file_get_parent (file);
diff --git a/src/nautilus-search-engine-simple.c b/src/nautilus-search-engine-simple.c
index 4fa1a0787..4dcd12b4e 100644
--- a/src/nautilus-search-engine-simple.c
+++ b/src/nautilus-search-engine-simple.c
@@ -330,7 +330,10 @@ visit_directory (GFile *dir,
goto next;
}
- is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
+ is_hidden = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) ||
+ g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
if (is_hidden && !nautilus_query_get_show_hidden_files (data->query))
{
goto next;
@@ -342,7 +345,8 @@ visit_directory (GFile *dir,
if (found && data->mime_types->len > 0)
{
- mime_type = g_file_info_get_content_type (info);
+ mime_type = g_file_info_get_attribute_string (info,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
found = FALSE;
for (gint i = 0; i < data->mime_types->len; i++)