diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-07-31 02:51:06 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-07-31 02:52:20 +0200 |
commit | 8437164dec2816d7a08faf14c29dd5cbe8b51d02 (patch) | |
tree | 52c4bfb2b9af6c55d9d8ac2f418db08a457771fd | |
parent | fec64d559512b2f2aae7b6041ece578c7d47f252 (diff) | |
download | fiv-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.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -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("-"); |