mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-18 14:48:53 +02:00
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.
This commit is contained in:
committed by
Philip Withnall
parent
40bcd3d9a5
commit
b4f6333783
35
gio/gfile.c
35
gio/gfile.c
@@ -534,37 +534,6 @@ g_file_get_path (GFile *file)
|
|||||||
return (* iface->get_path) (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 *
|
static const char *
|
||||||
file_peek_path_generic (GFile *file)
|
file_peek_path_generic (GFile *file)
|
||||||
{
|
{
|
||||||
@@ -591,10 +560,6 @@ file_peek_path_generic (GFile *file)
|
|||||||
if (path != NULL)
|
if (path != NULL)
|
||||||
break;
|
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)
|
if (new_path == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user