summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2017-08-15 10:12:33 +0200
committerOndrej Holy <oholy@redhat.com>2017-08-21 14:50:44 +0200
commitfbce9f8db631d6f0d95700f82b433e9f549090db (patch)
tree5fc8632c02d2b5bc94d3c1fa035b4417b5c0d0f8 /client
parent33f6ff08b5612f514ef3a6f11ddbf9b22bf0edc3 (diff)
downloadgvfs-fbce9f8db631d6f0d95700f82b433e9f549090db.tar.gz
gdaemonfile: Fix relative path handling
g_daemon_file_get_relative_path() fails for files with different mount_prefix and always return NULL. It happen when comparing two files from different origins, e.g. g_mount_get_root() and g_file_new_for_uri(). On the other hand, g_daemon_file_prefix_matches() can succeed in cases, where paths don't have the same prefixes, because it just compares mount_prefix of a parent with a path of a descendant, but a path of the parent is ignored. The code concatenates mount_prefix with a path, so the comparison never succeeds if mount_prefix is set, because mount_prefix is already part of the path in GDaemonFile. Let's ignore mount_prefix when comparing and always compare the paths, so we can significantly simplify the code. https://bugzilla.gnome.org/show_bug.cgi?id=786217
Diffstat (limited to 'client')
-rw-r--r--client/gdaemonfile.c68
1 files changed, 15 insertions, 53 deletions
diff --git a/client/gdaemonfile.c b/client/gdaemonfile.c
index 2807c801..d51c4c00 100644
--- a/client/gdaemonfile.c
+++ b/client/gdaemonfile.c
@@ -321,32 +321,21 @@ g_daemon_file_prefix_matches (GFile *parent,
GDaemonFile *descendant_daemon = G_DAEMON_FILE (descendant);
const char *remainder;
- if (descendant_daemon->mount_spec == parent_daemon->mount_spec)
+ /* If descendant was created with g_file_new_for_uri(), it's
+ * mount_prefix is /, but parent might have a different mount_prefix,
+ * for example if obtained by g_mount_get_root()
+ */
+ if (descendant_daemon->mount_spec == parent_daemon->mount_spec ||
+ g_mount_spec_match_with_path (parent_daemon->mount_spec,
+ descendant_daemon->mount_spec,
+ descendant_daemon->path))
{
remainder = match_prefix (descendant_daemon->path, parent_daemon->path);
if (remainder != NULL && *remainder == '/')
return TRUE;
- else
- return FALSE;
}
- else
- {
- /* If descendant was created with g_file_new_for_uri(), it's
- mount_prefix is /, but parent might have a different mount_prefix,
- for example if obtained by g_mount_get_root()
- */
- char *full_path;
- gboolean ok;
-
- full_path = g_build_path ("/", descendant_daemon->mount_spec->mount_prefix,
- descendant_daemon->path, NULL);
- ok = g_mount_spec_match_with_path (parent_daemon->mount_spec,
- descendant_daemon->mount_spec,
- full_path);
- g_free (full_path);
- return ok;
- }
+ return FALSE;
}
static char *
@@ -356,7 +345,11 @@ g_daemon_file_get_relative_path (GFile *parent,
GDaemonFile *parent_daemon = G_DAEMON_FILE (parent);
GDaemonFile *descendant_daemon = G_DAEMON_FILE (descendant);
- if (descendant_daemon->mount_spec == parent_daemon->mount_spec)
+ /* See comment in g_daemon_file_prefix_matches */
+ if (descendant_daemon->mount_spec == parent_daemon->mount_spec ||
+ g_mount_spec_match_with_path (parent_daemon->mount_spec,
+ descendant_daemon->mount_spec,
+ descendant_daemon->path))
{
const char *remainder;
@@ -364,40 +357,9 @@ g_daemon_file_get_relative_path (GFile *parent,
if (remainder != NULL && *remainder == '/')
return g_strdup (remainder + 1);
- else
- return NULL;
}
- else
- {
- char *full_path_descendant;
- char *full_path_parent;
- char *ret;
- const char *remainder;
- full_path_descendant = g_build_path ("/", descendant_daemon->mount_spec->mount_prefix,
- descendant_daemon->path, NULL);
-
- if (!g_mount_spec_match_with_path (parent_daemon->mount_spec,
- descendant_daemon->mount_spec,
- full_path_descendant))
- {
- g_free (full_path_descendant);
- return NULL;
- }
-
- full_path_parent = g_build_path ("/", parent_daemon->mount_spec->mount_prefix,
- parent_daemon->path, NULL);
-
- remainder = match_prefix (full_path_descendant, full_path_parent);
- if (remainder != NULL && *remainder == '/')
- ret = g_strdup (remainder + 1);
- else
- ret = NULL;
-
- g_free (full_path_parent);
- g_free (full_path_descendant);
- return ret;
- }
+ return NULL;
}
static GFile *