[glib/wip/oholy/peek-path-fixes: 138/139] gfile: Do not return target-uri from g_file_peek_path()



commit b4f63337835539555ff274aa6c3a008c4e93b25b
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Jan 29 14:30:02 2020 +0100

    gfile: Do not return target-uri from g_file_peek_path()
    
    Documentation says that g_file_peek_path() returns exactly the same
    what g_file_get_path(), but this is not true. Apart from that the code
    segfaults for some uris (e.g. for "trash:///"), it returns target-uri
    for trash and recent schemes. This is unexpected and can lead to various
    issues among others because the target-uri paths are not automatically
    translated back to GDaemonFile as it is done with gvfsd-fuse paths.
    g_file_get_path() returns NULL for trash and recent schemes, because
    fuse paths are not provided for those schemes. So g_file_peek_path()
    should return NULL as well. It is up to the concrete application to
    use target-uri when appropriate.
    
    This change was made as a part of commit 4808a957, however, neither
    the commit message, neither the corresponding bug doesn't mention this
    crucial change and doesn't give any clear reasoning. So let's revert
    this.

 gio/gfile.c | 37 +------------------------------------
 1 file changed, 1 insertion(+), 36 deletions(-)
---
diff --git a/gio/gfile.c b/gio/gfile.c
index c28939a49..597db9e1a 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -534,37 +534,6 @@ g_file_get_path (GFile *file)
   return (* iface->get_path) (file);
 }
 
-/* Original commit introducing this in libgsystem:
- *
- *  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
- */
-static char *
-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;
-}
-
 static const char *
 file_peek_path_generic (GFile *file)
 {
@@ -591,11 +560,7 @@ file_peek_path_generic (GFile *file)
       if (path != NULL)
         break;
 
-      if (g_file_has_uri_scheme (file, "trash") ||
-          g_file_has_uri_scheme (file, "recent"))
-        new_path = file_get_target_path (file);
-      else
-        new_path = g_file_get_path (file);
+      new_path = g_file_get_path (file);
       if (new_path == NULL)
         return NULL;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]