Merge branch '2948-gio-is-hidden' into 'main'

gio: Add some missing file info attribute checks in gio-list and gio-tree

Closes #2948

See merge request GNOME/glib!3336
This commit is contained in:
Marco Trevisan 2023-03-21 14:47:47 +00:00
commit fc5fc89841
5 changed files with 22 additions and 9 deletions

View File

@ -1838,6 +1838,7 @@ g_file_info_get_modification_time (GFileInfo *info,
if (G_UNLIKELY (value == NULL))
{
g_critical ("GFileInfo created without " G_FILE_ATTRIBUTE_TIME_MODIFIED);
result->tv_sec = result->tv_usec = 0;
g_return_if_reached ();
}

View File

@ -157,7 +157,8 @@ show_info (GFile *file, GFileInfo *info)
GUnixMountEntry *entry;
#endif
name = g_file_info_get_display_name (info);
name = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME) ?
g_file_info_get_display_name (info) : NULL;
if (name)
{
/* Translators: This is a noun and represents and attribute of a file */
@ -166,7 +167,8 @@ show_info (GFile *file, GFileInfo *info)
g_free (flatten);
}
name = g_file_info_get_edit_name (info);
name = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) ?
g_file_info_get_edit_name (info) : NULL;
if (name)
{
/* Translators: This is a noun and represents and attribute of a file */

View File

@ -54,10 +54,12 @@ show_file_listing (GFileInfo *info, GFile *parent)
gboolean first_attr;
GFile *child;
if ((g_file_info_get_is_hidden (info)) && !show_hidden)
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) &&
g_file_info_get_is_hidden (info) &&
!show_hidden)
return;
if (print_display_names)
if (print_display_names && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME))
name = g_file_info_get_display_name (info);
else
name = g_file_info_get_name (info);
@ -71,7 +73,8 @@ show_file_listing (GFileInfo *info, GFile *parent)
g_object_unref (child);
}
size = g_file_info_get_size (info);
size = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE) ?
g_file_info_get_size (info) : 0;
type = file_type_to_string (g_file_info_get_file_type (info));
if (show_long)
g_print ("%s\t%"G_GUINT64_FORMAT"\t(%s)", print_uris? uri: name, (guint64)size, type);

View File

@ -95,7 +95,9 @@ do_tree (GFile *f, unsigned int level, guint64 pattern)
info_list = NULL;
while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
{
if (g_file_info_get_is_hidden (info) && !show_hidden)
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) &&
g_file_info_get_is_hidden (info) &&
!show_hidden)
{
g_object_unref (info);
}
@ -151,7 +153,8 @@ do_tree (GFile *f, unsigned int level, guint64 pattern)
}
else
{
if (g_file_info_get_is_symlink (info))
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK) &&
g_file_info_get_is_symlink (info))
{
const char *target;
target = g_file_info_get_symlink_target (info);
@ -162,7 +165,9 @@ do_tree (GFile *f, unsigned int level, guint64 pattern)
g_print ("\n");
if ((type & G_FILE_TYPE_DIRECTORY) &&
(follow_symlinks || !g_file_info_get_is_symlink (info)))
(follow_symlinks ||
!(g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK) &&
g_file_info_get_is_symlink (info))))
{
guint64 new_pattern;
GFile *child;

View File

@ -94,7 +94,9 @@ calc_event_type (GFileInfo *last,
g_strcmp0 (g_file_info_get_etag (last), g_file_info_get_etag (new)) != 0)
return G_FILE_MONITOR_EVENT_CHANGED;
if (g_file_info_get_size (last) != g_file_info_get_size (new))
if (g_file_info_has_attribute (last, G_FILE_ATTRIBUTE_STANDARD_SIZE) &&
g_file_info_has_attribute (new, G_FILE_ATTRIBUTE_STANDARD_SIZE) &&
g_file_info_get_size (last) != g_file_info_get_size (new))
return G_FILE_MONITOR_EVENT_CHANGED;
return -1;