gvfs/gvfs-1.3.5-mountspec-prefix-ensure-ending-path-separator.patch

86 lines
2.6 KiB
Diff

From 3e62465b2aee2ca71302f00ccf815a48e87626ee Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Thu, 13 Aug 2009 15:30:35 +0200
Subject: [PATCH] Always set mount prefix ending with path separator
Mount prefix should always end with path separator ("/") to prevent
duplicate mounts, which would only have different prefix strings
(e.g. one with "/subdir" and the other with "/subdir/").
---
common/gmountspec.c | 30 +++++++++++++++++++++++++-----
1 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/common/gmountspec.c b/common/gmountspec.c
index d72e189..16c0e66 100644
--- a/common/gmountspec.c
+++ b/common/gmountspec.c
@@ -42,6 +42,19 @@ item_compare (const void *_a, const void *_b)
return strcmp (a->key, b->key);
}
+/*
+ * Ensure trailing "/" to avoid redirections and mount_spec duplication.
+ * Returns newly allocated string.
+ */
+static gchar *
+ensure_trailing_path_separator (const gchar *path)
+{
+ if (path == NULL || g_str_has_suffix (path, "/"))
+ return g_strdup (path);
+ else
+ return g_strconcat (path, "/", NULL);
+}
+
GMountSpec *
g_mount_spec_new (const char *type)
{
@@ -69,9 +82,14 @@ g_mount_spec_new_from_data (GArray *items,
spec->ref_count = 1;
spec->items = items;
if (mount_prefix == NULL)
- spec->mount_prefix = g_strdup ("/");
+ {
+ spec->mount_prefix = g_strdup ("/");
+ }
else
- spec->mount_prefix = mount_prefix;
+ {
+ spec->mount_prefix = ensure_trailing_path_separator (mount_prefix);
+ g_free (mount_prefix);
+ }
g_array_sort (spec->items, item_compare);
@@ -112,7 +130,7 @@ g_mount_spec_set_mount_prefix (GMountSpec *spec,
const char *mount_prefix)
{
g_free (spec->mount_prefix);
- spec->mount_prefix = g_strdup (mount_prefix);
+ spec->mount_prefix = ensure_trailing_path_separator (mount_prefix);
}
@@ -247,7 +265,8 @@ g_mount_spec_from_dbus (DBusMessageIter *iter)
spec = g_mount_spec_new (NULL);
g_free (spec->mount_prefix);
- spec->mount_prefix = mount_prefix;
+ spec->mount_prefix = ensure_trailing_path_separator (mount_prefix);
+ g_free (mount_prefix);
if (dbus_message_iter_get_arg_type (&spec_iter) != DBUS_TYPE_ARRAY ||
dbus_message_iter_get_element_type (&spec_iter) != DBUS_TYPE_STRUCT)
@@ -541,7 +560,8 @@ g_mount_spec_new_from_string (const gchar *str,
if (strcmp (tokens[0], "prefix") == 0)
{
g_free (item.key);
- mount_prefix = item.value;
+ mount_prefix = ensure_trailing_path_separator (item.value);
+ g_free (item.value);
}
else
{
--
1.6.4