summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2007-10-31 15:54:30 +0000
committerAlexander Larsson <alexl@src.gnome.org>2007-10-31 15:54:30 +0000
commit7f5e177a24c1b96d0fce7b9f1ac9b1758e619593 (patch)
treefec012b471750e1109f90a04a68e369976ff857f
parentd6ce9fc4cf74aa567a9b83074a44f9aba0398f56 (diff)
downloadgvfs-7f5e177a24c1b96d0fce7b9f1ac9b1758e619593.tar.gz
Implement contains_file and get_relative_path
2007-10-31 Alexander Larsson <alexl@redhat.com> * client/gdaemonfile.c: Implement contains_file and get_relative_path svn path=/trunk/; revision=1005
-rw-r--r--ChangeLog5
-rw-r--r--client/gdaemonfile.c49
2 files changed, 54 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 0705be8a..0e83813a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2007-10-31 Alexander Larsson <alexl@redhat.com>
+ * client/gdaemonfile.c:
+ Implement contains_file and get_relative_path
+
+2007-10-31 Alexander Larsson <alexl@redhat.com>
+
* daemon/gvfsbackend.[ch]:
Add g_vfs_backend_get_mount_spec
diff --git a/client/gdaemonfile.c b/client/gdaemonfile.c
index dec1b1c3..73a28b4c 100644
--- a/client/gdaemonfile.c
+++ b/client/gdaemonfile.c
@@ -290,6 +290,53 @@ g_daemon_file_equal (GFile *file1,
g_str_equal (daemon_file1->path, daemon_file2->path);
}
+
+static const char *
+match_prefix (const char *path, const char *prefix)
+{
+ int prefix_len;
+
+ prefix_len = strlen (prefix);
+ if (strncmp (path, prefix, prefix_len) != 0)
+ return NULL;
+ return path + prefix_len;
+}
+
+static gboolean
+g_daemon_file_contains_file (GFile *parent,
+ GFile *descendant)
+{
+ GDaemonFile *parent_daemon = G_DAEMON_FILE (parent);
+ GDaemonFile *descendant_daemon = G_DAEMON_FILE (descendant);
+ const char *remainder;
+
+ if (descendant_daemon->mount_spec != parent_daemon->mount_spec)
+ return FALSE;
+
+ remainder = match_prefix (descendant_daemon->path, parent_daemon->path);
+ if (remainder != NULL && *remainder == '/')
+ return TRUE;
+ return FALSE;
+}
+
+static char *
+g_daemon_file_get_relative_path (GFile *parent,
+ GFile *descendant)
+{
+ GDaemonFile *parent_daemon = G_DAEMON_FILE (parent);
+ GDaemonFile *descendant_daemon = G_DAEMON_FILE (descendant);
+ const char *remainder;
+
+ if (descendant_daemon->mount_spec != parent_daemon->mount_spec)
+ return NULL;
+
+ remainder = match_prefix (descendant_daemon->path, parent_daemon->path);
+
+ if (remainder != NULL && *remainder == '/')
+ return g_strdup (remainder + 1);
+ return NULL;
+}
+
static GFile *
g_daemon_file_resolve_relative_path (GFile *file,
const char *relative_path)
@@ -1868,6 +1915,8 @@ g_daemon_file_file_iface_init (GFileIface *iface)
iface->get_uri = g_daemon_file_get_uri;
iface->get_parse_name = g_daemon_file_get_parse_name;
iface->get_parent = g_daemon_file_get_parent;
+ iface->contains_file = g_daemon_file_contains_file;
+ iface->get_relative_path = g_daemon_file_get_relative_path;
iface->resolve_relative_path = g_daemon_file_resolve_relative_path;
iface->get_child_for_display_name = g_daemon_file_get_child_for_display_name;
iface->enumerate_children = g_daemon_file_enumerate_children;