diff options
author | Bastien Nocera <hadess@hadess.net> | 2013-09-20 12:59:23 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2013-09-20 20:47:03 +0200 |
commit | 66140c018f044ba038ddb6bc1e6e97eb87d2b8f6 (patch) | |
tree | f3be1a76e3df6b4fcb1f44610f55cdaa86ee5110 | |
parent | e0b2fefbb69d03f7aa1390f723e4dfc46f301e71 (diff) | |
download | libgsystem-66140c018f044ba038ddb6bc1e6e97eb87d2b8f6.tar.gz |
fileutil: Handle recent: and trash: URIs
The gs_file_get_path_cached() was rather brittle in its handling
of URIs. It would assert() when a GFile didn't have a backing path
(such as when handling trash: or recent: URIs), and didn't know
how to get the target URI for those items either.
Make sure that we do not assert() when a backing path cannot be
found, and handle recent: and trash: URIs.
https://bugzilla.gnome.org/show_bug.cgi?id=708435
-rw-r--r-- | gsystem-file-utils.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c index 18b7bc1..7894aee 100644 --- a/gsystem-file-utils.c +++ b/gsystem-file-utils.c @@ -762,6 +762,23 @@ gs_file_linkcopy_sync_data (GFile *src, return linkcopy_internal (src, dest, flags, TRUE, cancellable, error); } +static char * +gs_file_get_target_path (GFile *file) +{ + GFileInfo *info; + const char *target; + char *path; + + info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, G_FILE_QUERY_INFO_NONE, NULL, NULL); + if (info == NULL) + return NULL; + target = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); + path = g_filename_from_uri (target, NULL, NULL); + g_object_unref (info); + + return path; +} + G_LOCK_DEFINE_STATIC (pathname_cache); /** @@ -784,8 +801,13 @@ gs_file_get_path_cached (GFile *file) path = g_object_get_qdata ((GObject*)file, _file_path_quark); if (!path) { - path = g_file_get_path (file); - g_assert (path != NULL); + if (g_file_has_uri_scheme (file, "trash") || + g_file_has_uri_scheme (file, "recent")) + path = gs_file_get_target_path (file); + else + path = g_file_get_path (file); + if (path == NULL) + return NULL; g_object_set_qdata_full ((GObject*)file, _file_path_quark, (char*)path, (GDestroyNotify)g_free); } |