summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2020-09-10 13:00:41 +0100
committerPhilip Withnall <withnall@endlessm.com>2020-09-10 14:14:32 +0100
commit6f9b379c08bcb12a91b1fc01c9c113c9b7975361 (patch)
treea138fac10f986929228921af3481150a786fbd55
parentc2c12e42920d6e06c23c87398996827e53c1fc72 (diff)
downloadglib-6f9b379c08bcb12a91b1fc01c9c113c9b7975361.tar.gz
gwinhttpfile: Set display-name attribute on file info
It is not allowed to be `NULL` or unset if requested by the file attribute matcher. Derive it from the basename. This doesn’t handle the situation of a failed UTF-16 to UTF-8 conversion very well, but will at least return something. Note that the `g_filename_display_basename()` function can’t be used as `GWinHttpFile` provides its URI in UTF-16 rather than in the file system encoding. This fixes a crash when using GIMP on Windows. Thanks to lillolollo for in-depth debugging assistance. Signed-off-by: Philip Withnall <withnall@endlessm.com> Fixes: #2194
-rw-r--r--gio/win32/gwinhttpfile.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c
index cf5eed31d..509cdeb33 100644
--- a/gio/win32/gwinhttpfile.c
+++ b/gio/win32/gwinhttpfile.c
@@ -29,6 +29,7 @@
#include "gio/gfile.h"
#include "gio/gfileattribute.h"
#include "gio/gfileinfo.h"
+#include "gio/gfileinfo-priv.h"
#include "gwinhttpfile.h"
#include "gwinhttpfileinputstream.h"
#include "gwinhttpfileoutputstream.h"
@@ -178,6 +179,21 @@ g_winhttp_file_get_basename (GFile *file)
}
static char *
+g_winhttp_file_get_display_name (GFile *file)
+{
+ char *basename;
+
+ /* FIXME: This could be improved by using a new g_utf16_make_valid() function
+ * to recover what we can from the URI, and then suffixing it with
+ * “ (invalid encoding)” as per g_filename_display_basename(). */
+ basename = g_winhttp_file_get_basename (file);
+ if (!basename)
+ return g_strdup (_(" (invalid encoding)"));
+
+ return g_steal_pointer (&basename);
+}
+
+static char *
g_winhttp_file_get_path (GFile *file)
{
return NULL;
@@ -513,6 +529,14 @@ g_winhttp_file_query_info (GFile *file,
g_file_info_set_name (info, basename);
g_free (basename);
+ if (_g_file_attribute_matcher_matches_id (matcher,
+ G_FILE_ATTRIBUTE_ID_STANDARD_DISPLAY_NAME))
+ {
+ char *display_name = g_winhttp_file_get_display_name (file);
+ g_file_info_set_display_name (info, display_name);
+ g_free (display_name);
+ }
+
content_length = NULL;
if (_g_winhttp_query_header (winhttp_file->vfs,
request,