[PATCH] Modify gnome_vfs_uri_extract_dirname behavior
- From: Christian Neumair <chris gnome-de org>
- To: gnome-vfs-list gnome org
- Subject: [PATCH] Modify gnome_vfs_uri_extract_dirname behavior
- Date: Tue, 21 Mar 2006 18:06:45 +0100
The attached patch is meant to fix bug 310656 [1] by ensuring that
extract_dirname behaves as documented. It also documents
gnome_vfs_uri_get_parent, and adds two FIXME comments to these
functions. Things I plan for the future to clean up the code:
a) uri->text should never be NULL (cf. RFC 2396, should be empty) -
that's why the docs I added talk about empty paths but not about NULL
paths. Many methods will need fixing, this shouldn't be done before
2.15.
b) uri->query should be added, and the URI split correctly upon
creation, instead of adding it to uri->text and scanning for it.
[1] http://bugzilla.gnome.org/show_bug.cgi?id=310656
--
Christian Neumair <chris gnome-de org>
Index: libgnomevfs/gnome-vfs-uri.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-uri.c,v
retrieving revision 1.133
diff -u -p -r1.133 gnome-vfs-uri.c
--- libgnomevfs/gnome-vfs-uri.c 27 Feb 2006 10:25:39 -0000 1.133
+++ libgnomevfs/gnome-vfs-uri.c 21 Mar 2006 17:05:01 -0000
@@ -1335,6 +1453,20 @@ gnome_vfs_uri_has_parent (const GnomeVFS
* @uri: a #GnomeVFSURI.
*
* Retrieve @uri's parent uri.
+ *
+ * If the @uri's path not empty, does not exclusively consist of
+ * %GNOME_VFS_URI_PATH_CHR characters, but contains at least one
+ * %GNOME_VFS_URI_PATH_CHR character, a #GnomeVFSURI pointing to
+ * the parent path of the @uri path will be returned. It is
+ * computed by stripping off any trailing %GNOME_VFS_URI_PATH_CHR
+ * characters, and removing everything after the last
+ * %GNOME_VFS_URI_PATH_CHR characters from the remaining string.
+ *
+ * If the @uri's path is empty, only consists of %GNOME_VFS_URI_PATH_CHR
+ * characters or does not contain any %GNOME_VFS_URI_PATH_CHR character, a
+ * duplicate of the parent pointer in the #GnomeVFSURI struct of @uri
+ * is returned, which is %NULL if @uri is not chained, and the parent of
+ * the chained @uri otherwise.
*
* Return value: a pointer to @uri's parent uri.
*/
@@ -1344,6 +1476,7 @@ gnome_vfs_uri_get_parent (const GnomeVFS
g_return_val_if_fail (uri != NULL, NULL);
if (uri->text != NULL && strchr (uri->text, GNOME_VFS_URI_PATH_CHR) != NULL) {
+ /* FIXME this does not ensure that we don't operate on the query! */
gchar *p;
guint len;
@@ -1796,8 +1929,23 @@ gnome_vfs_uri_get_fragment_identifier (c
* @uri: a #GnomeVFSURI.
*
* Extract the name of the directory in which the file pointed to by @uri is
- * stored as a newly allocated string. The string will end with a
- * %GNOME_VFS_URI_PATH_CHR.
+ * stored as a newly allocated string. The string will be %NULL or end with
+ * a %GNOME_VFS_URI_PATH_CHR character. This does not match the POSIX 1003.1
+ * definition of dirname.
+ *
+ * If the path of @uri is empty, %NULL is returned.
+ *
+ * If the path of @uri is %GNOME_VFS_URI_PATH_STR, or does not contain any
+ * %GNOME_VFS_URI_PATH_CHR character, %GNOME_VFS_URI_PATH_STR is returned.
+ *
+ * Otherwise, a copy of the path is returned, after truncating everything
+ * after the last %GNOME_VFS_URI_PATH_CHR occurence. Note that if the path
+ * already ends in %GNOME_VFS_URI_PATH_CHR, an identical copy of the path
+ * will be returned.
+ *
+ * Conceptually, this function is similar to gnome_vfs_uri_get_parent().
+ * If you want to further operate on the parent of @uri, you should use
+ * gnome_vfs_uri_get_parent().
*
* Return value: a pointer to the newly allocated string representing the
* parent directory.
@@ -1809,17 +1957,19 @@ gnome_vfs_uri_extract_dirname (const Gno
g_return_val_if_fail (uri != NULL, NULL);
- if (uri->text == NULL) {
+ /* FIXME this does not ensure that we don't operate on the query! */
+
+ if (uri->text == NULL || !strcmp (uri->text, "")) {
return NULL;
}
base = strrchr (uri->text, GNOME_VFS_URI_PATH_CHR);
- if (base == NULL || base == uri->text) {
+ if (base == NULL) {
return g_strdup (GNOME_VFS_URI_PATH_STR);
}
- return g_strndup (uri->text, base - uri->text);
+ return g_strndup (uri->text, base - uri->text + 1);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]