diff options
author | Ondrej Holy <oholy@redhat.com> | 2023-03-07 14:50:22 +0100 |
---|---|---|
committer | Ondrej Holy <oholy@redhat.com> | 2023-03-09 14:06:07 +0000 |
commit | 6dcfe48857f0e9574cc4066b296391c6f806260a (patch) | |
tree | 275a077000b2ef9b6705e76786eff7a2d9c2c03f | |
parent | d73bd43a078b5fc849f7b3be3d2c56b348ead354 (diff) | |
download | nautilus-6dcfe48857f0e9574cc4066b296391c6f806260a.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.c | 15 | ||||
-rw-r--r-- | src/nautilus-file.c | 22 | ||||
-rw-r--r-- | src/nautilus-search-engine-recent.c | 9 | ||||
-rw-r--r-- | src/nautilus-search-engine-simple.c | 8 |
4 files changed, 39 insertions, 15 deletions
diff --git a/src/nautilus-directory-async.c b/src/nautilus-directory-async.c index 0e930d507..7436a6949 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 caf0b4e69..ee1ff57c9 100644 --- a/src/nautilus-file.c +++ b/src/nautilus-file.c @@ -2477,6 +2477,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) { @@ -2505,9 +2506,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); @@ -2552,14 +2555,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; @@ -2784,7 +2791,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; @@ -2843,7 +2851,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; @@ -2851,7 +2860,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++) |