From 4e62e55d6d0109012869a589eae2371e836e9cb3 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 6 Mar 2023 13:02:41 +0000 Subject: [PATCH] gfile: Check ETag attribute is present before trying to get it A regression from issue #2907. Signed-off-by: Philip Withnall Fixes: #2932 --- gio/gfile.c | 4 ++-- gio/gpollfilemonitor.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/gio/gfile.c b/gio/gfile.c index 84353cb44..7cfe1ffb4 100644 --- a/gio/gfile.c +++ b/gio/gfile.c @@ -7773,7 +7773,7 @@ g_file_load_contents (GFile *file, NULL); if (info) { - *etag_out = g_strdup (g_file_info_get_etag (info)); + *etag_out = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ETAG_VALUE) ? g_strdup (g_file_info_get_etag (info)) : NULL; g_object_unref (info); } } @@ -7847,7 +7847,7 @@ load_contents_fstat_callback (GObject *obj, stat_res, NULL); if (info) { - data->etag = g_strdup (g_file_info_get_etag (info)); + data->etag = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ETAG_VALUE) ? g_strdup (g_file_info_get_etag (info)) : NULL; g_object_unref (info); } diff --git a/gio/gpollfilemonitor.c b/gio/gpollfilemonitor.c index 685ede964..c4dfd9913 100644 --- a/gio/gpollfilemonitor.c +++ b/gio/gpollfilemonitor.c @@ -89,7 +89,9 @@ calc_event_type (GFileInfo *last, if (last != NULL && new == NULL) return G_FILE_MONITOR_EVENT_DELETED; - if (g_strcmp0 (g_file_info_get_etag (last), g_file_info_get_etag (new))) + if (g_file_info_has_attribute (last, G_FILE_ATTRIBUTE_ETAG_VALUE) && + g_file_info_has_attribute (new, G_FILE_ATTRIBUTE_ETAG_VALUE) && + 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))