aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-07-31 02:51:06 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-07-31 02:52:20 +0200
commit8437164dec2816d7a08faf14c29dd5cbe8b51d02 (patch)
tree52c4bfb2b9af6c55d9d8ac2f418db08a457771fd
parentfec64d559512b2f2aae7b6041ece578c7d47f252 (diff)
downloadfiv-8437164dec2816d7a08faf14c29dd5cbe8b51d02.tar.gz
fiv-8437164dec2816d7a08faf14c29dd5cbe8b51d02.tar.xz
fiv-8437164dec2816d7a08faf14c29dd5cbe8b51d02.zip
Try a bit harder to get a file's local path
-rw-r--r--fiv-view.c25
1 files changed, 24 insertions, 1 deletions
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("-");