glib r6546 - in trunk/gio: . tests



Author: alexl
Date: Thu Feb 21 09:09:59 2008
New Revision: 6546
URL: http://svn.gnome.org/viewvc/glib?rev=6546&view=rev

Log:
2008-02-21  Alexander Larsson  <alexl redhat com>

        * gfile.[ch]:
        * gio.symbols:
	Add new g_file_has_prefix that does the same as g_file_contains_file.
	Deprecate g_file_contains_file and add a macro that converts
	it to g_file_has_prefix.
	The reason for this change is that the contains_file() name seems to
	imply that this does more work than what it does, but its really only
	a name match (from #517086)
	
        * gdummyfile.c:
        * glocalfile.c:
        * tests/g-file.c:
	Update to match the above change.



Modified:
   trunk/gio/ChangeLog
   trunk/gio/gdummyfile.c
   trunk/gio/gfile.c
   trunk/gio/gfile.h
   trunk/gio/gio.symbols
   trunk/gio/glocalfile.c
   trunk/gio/tests/g-file.c

Modified: trunk/gio/gdummyfile.c
==============================================================================
--- trunk/gio/gdummyfile.c	(original)
+++ trunk/gio/gdummyfile.c	Thu Feb 21 09:09:59 2008
@@ -261,8 +261,7 @@
 }
 
 static gboolean
-g_dummy_file_contains_file (GFile *parent,
-			    GFile *descendant)
+g_dummy_file_prefix_matches (GFile *parent, GFile *descendant)
 {
   GDummyFile *parent_dummy = G_DUMMY_FILE (parent);
   GDummyFile *descendant_dummy = G_DUMMY_FILE (descendant);
@@ -425,7 +424,7 @@
   iface->get_uri = g_dummy_file_get_uri;
   iface->get_parse_name = g_dummy_file_get_parse_name;
   iface->get_parent = g_dummy_file_get_parent;
-  iface->contains_file = g_dummy_file_contains_file;
+  iface->prefix_matches = g_dummy_file_prefix_matches;
   iface->get_relative_path = g_dummy_file_get_relative_path;
   iface->resolve_relative_path = g_dummy_file_resolve_relative_path;
   iface->get_child_for_display_name = g_dummy_file_get_child_for_display_name;

Modified: trunk/gio/gfile.c
==============================================================================
--- trunk/gio/gfile.c	(original)
+++ trunk/gio/gfile.c	Thu Feb 21 09:09:59 2008
@@ -617,32 +617,60 @@
   return (* iface->get_child_for_display_name) (file, display_name, error);
 }
 
+#undef g_file_contains_file
+
 /**
  * g_file_contains_file:
  * @parent: input #GFile.
  * @descendant: input #GFile.
- * 
- * Checks whether @parent (recursively) contains the specified @descendant.
- * 
- * This call does no blocking i/o.
- * 
+ *
+ * Deprecated version of g_file_has_prefix().
+ *
  * Returns:  %TRUE if the @descendant's parent, grandparent, etc is @parent. %FALSE otherwise.
- **/
+ *
+ * Deprecated:2.16: The initial chosen name was unfortunate, as it
+ * may cause you to think this function did more than just
+ * filename comparisons.
+ */
 gboolean
 g_file_contains_file (GFile *parent,
 		      GFile *descendant)
 {
+  /* This function is not in the header and will not be referenced by newly built code */
+  return g_file_has_prefix (descendant, parent);
+}
+
+/**
+ * g_file_has_prefix:
+ * @file: input #GFile.
+ * @prefix: input #GFile.
+ * 
+ * Checks whether @file has the prefix specified by @prefix. In other word, if the
+ * inital elements of @file<!-- -->s pathname match @prefix.
+ * 
+ * This call does no i/o, as it works purely on names. As such it can sometimes
+ * return %FALSE even if @file is inside a @prefix (from a filesystem point of view),
+ * because the prefix of @file is an alias of @prefix.
+ *
+ * Returns:  %TRUE if the @files's parent, grandparent, etc is @prefix. %FALSE otherwise.
+ **/
+gboolean
+g_file_has_prefix (GFile *file,
+		   GFile *prefix)
+{
   GFileIface *iface;
   
-  g_return_val_if_fail (G_IS_FILE (parent), FALSE);
-  g_return_val_if_fail (G_IS_FILE (descendant), FALSE);
+  g_return_val_if_fail (G_IS_FILE (file), FALSE);
+  g_return_val_if_fail (G_IS_FILE (prefix), FALSE);
 
-  if (G_TYPE_FROM_INSTANCE (parent) != G_TYPE_FROM_INSTANCE (descendant))
+  if (G_TYPE_FROM_INSTANCE (file) != G_TYPE_FROM_INSTANCE (prefix))
     return FALSE;
   
-  iface = G_FILE_GET_IFACE (parent);
+  iface = G_FILE_GET_IFACE (file);
 
-  return (* iface->contains_file) (parent, descendant);
+  /* The vtable function differs in arg order since we're
+     using the old contains_file call */
+  return (* iface->prefix_matches) (prefix, file);
 }
 
 /**

Modified: trunk/gio/gfile.h
==============================================================================
--- trunk/gio/gfile.h	(original)
+++ trunk/gio/gfile.h	Thu Feb 21 09:09:59 2008
@@ -187,7 +187,7 @@
  * @get_uri: Gets a URI for the path within a #GFile.
  * @get_parse_name: Gets the parsed name for the #GFile.
  * @get_parent: Gets the parent directory for the #GFile.
- * @contains_file: Checks whether a #GFile contains a specified file.
+ * @prefix_matches: Checks whether a #GFile contains a specified file.
  * @get_relative_path: Gets the path for a #GFile relative to a given path.
  * @resolve_relative_path: Resolves a relative path for a #GFile to an absolute path.
  * @get_child_for_display_name: Gets the child #GFile for a given display name.
@@ -278,8 +278,8 @@
   char *              (*get_uri)                    (GFile         *file);
   char *              (*get_parse_name)             (GFile         *file);
   GFile *             (*get_parent)                 (GFile         *file);
-  gboolean            (*contains_file)              (GFile         *parent,
-						     GFile         *descendant);
+  gboolean            (*prefix_matches)             (GFile         *prefix,
+						     GFile         *file);
   char *              (*get_relative_path)          (GFile         *parent,
 						     GFile         *descendant);
   GFile *             (*resolve_relative_path)      (GFile        *file,
@@ -573,8 +573,11 @@
 GFile *                 g_file_get_child_for_display_name (GFile                      *file,
 							   const char                 *display_name,
 							   GError                    **error);
-gboolean                g_file_contains_file              (GFile                      *parent,
-							   GFile                      *descendant);
+#ifndef G_DISABLE_DEPRECATED
+#define g_file_contains_file(_parent, _child)  g_file_has_prefix (_child, _parent)
+#endif
+gboolean                g_file_has_prefix                 (GFile                      *file,
+							   GFile                      *prefix);
 char *                  g_file_get_relative_path          (GFile                      *parent,
 							   GFile                      *descendant);
 GFile *                 g_file_resolve_relative_path      (GFile                      *file,

Modified: trunk/gio/gio.symbols
==============================================================================
--- trunk/gio/gio.symbols	(original)
+++ trunk/gio/gio.symbols	Thu Feb 21 09:09:59 2008
@@ -230,7 +230,7 @@
 g_file_get_parent
 g_file_get_child
 g_file_get_child_for_display_name
-g_file_contains_file
+g_file_has_prefix
 g_file_get_relative_path
 g_file_resolve_relative_path
 g_file_is_native

Modified: trunk/gio/glocalfile.c
==============================================================================
--- trunk/gio/glocalfile.c	(original)
+++ trunk/gio/glocalfile.c	Thu Feb 21 09:09:59 2008
@@ -519,8 +519,8 @@
 }
 
 static gboolean
-g_local_file_contains_file (GFile *parent,
-			    GFile *descendant)
+g_local_file_prefix_matches (GFile *parent,
+			     GFile *descendant)
 {
   GLocalFile *parent_local = G_LOCAL_FILE (parent);
   GLocalFile *descendant_local = G_LOCAL_FILE (descendant);
@@ -1977,7 +1977,7 @@
   iface->get_uri = g_local_file_get_uri;
   iface->get_parse_name = g_local_file_get_parse_name;
   iface->get_parent = g_local_file_get_parent;
-  iface->contains_file = g_local_file_contains_file;
+  iface->prefix_matches = g_local_file_prefix_matches;
   iface->get_relative_path = g_local_file_get_relative_path;
   iface->resolve_relative_path = g_local_file_resolve_relative_path;
   iface->get_child_for_display_name = g_local_file_get_child_for_display_name;

Modified: trunk/gio/tests/g-file.c
==============================================================================
--- trunk/gio/tests/g-file.c	(original)
+++ trunk/gio/tests/g-file.c	Thu Feb 21 09:09:59 2008
@@ -348,12 +348,12 @@
 }
 
 static char*
-get_relative_path (const gboolean use_uri, const gboolean should_contain_file, const char *dir1, const char *dir2)
+get_relative_path (const gboolean use_uri, const gboolean should_have_prefix, const char *dir1, const char *dir2)
 {
   GFile *file1 = NULL;
   GFile *file2 = NULL;
   GFile *file3 = NULL;
-  gboolean contains_file = FALSE;
+  gboolean has_prefix = FALSE;
   char *relative_path = NULL;
   
   if (use_uri)
@@ -370,12 +370,12 @@
   g_assert (file1 != NULL);
   g_assert (file2 != NULL);
   
-  contains_file = g_file_contains_file (file1, file2);
+  has_prefix = g_file_has_prefix (file2, file1);
   g_print ("%s %s\n", dir1, dir2);
-  g_assert (contains_file == should_contain_file);
+  g_assert (has_prefix == should_have_prefix);
 
   relative_path = g_file_get_relative_path (file1, file2);
-  if (should_contain_file)
+  if (should_have_prefix)
     {
       g_assert (relative_path != NULL);
       
@@ -394,7 +394,7 @@
 }
 
 static void
-test_g_file_contains_file (void)
+test_g_file_has_prefix (void)
 {
   /*  TestPathsWithOper.equal represents here if the dir belongs to the directory structure  */
   const struct TestPathsWithOper dirs[] =
@@ -528,8 +528,8 @@
   /*  Testing g_file_new_for_commandline_arg() for correct relavive path resolution and correct path/URI guess   */
   g_test_add_func ("/g-file/test_g_file_new_for_commandline_arg", test_g_file_new_for_commandline_arg);
   
-  /*  Testing g_file_contains_file(), g_file_get_relative_path() and g_file_resolve_relative_path() to return and process correct relative paths         */
-  g_test_add_func ("/g-file/test_g_file_contains_file", test_g_file_contains_file);
+  /*  Testing g_file_has_prefix(), g_file_get_relative_path() and g_file_resolve_relative_path() to return and process correct relative paths         */
+  g_test_add_func ("/g-file/test_g_file_has_prefix", test_g_file_has_prefix);
   
   /*  Testing g_file_get_parent() and g_file_get_child()            */
   g_test_add_func ("/g-file/test_g_file_get_parent_child", test_g_file_get_parent_child);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]