From 8437164dec2816d7a08faf14c29dd5cbe8b51d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Sun, 31 Jul 2022 02:51:06 +0200 Subject: Try a bit harder to get a file's local path --- fiv-view.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/fiv-view.c b/fiv-view.c index 4da10d3..6255e75 100644 --- a/fiv-view.c +++ b/fiv-view.c @@ -1201,6 +1201,29 @@ info_parse(char *tsv) return vbox; } +// Several GVfs schemes contain pseudo-symlinks that don't give out +// filesystem paths directly. +static gchar * +get_target_path(GFile *file, GCancellable *cancellable) +{ + GFileInfo *info = + g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, + G_FILE_QUERY_INFO_NONE, cancellable, NULL); + if (!info) + return NULL; + + gchar *path = NULL; + const char *target_uri = g_file_info_get_attribute_string( + info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); + if (target_uri) { + GFile *target = g_file_new_for_uri(target_uri); + path = g_file_get_path(target); + g_object_unref(target); + } + g_object_unref(info); + return path; +} + static void info(FivView *self) { @@ -1218,7 +1241,7 @@ info(FivView *self) GBytes *inbytes = NULL, *outbytes = NULL, *errbytes = NULL; gchar *file_data = NULL; gsize file_len = 0; - if (!path && + if (!path && !(path = get_target_path(file, NULL)) && g_file_load_contents(file, NULL, &file_data, &file_len, NULL, &error)) { flags |= G_SUBPROCESS_FLAGS_STDIN_PIPE; path = g_strdup("-"); -- cgit v1.2.3