Add new g_file_has_prefix that does the same as g_file_contains_file.

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.


svn path=/trunk/; revision=6546
This commit is contained in:
Alexander Larsson 2008-02-21 09:09:59 +00:00 committed by Alexander Larsson
parent 03c51e95a7
commit 6dc9b7ee00
7 changed files with 77 additions and 31 deletions

View File

@ -1,3 +1,19 @@
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.
2008-02-20 Benjamin Otte <otte@gnome.org>
* gfile.c: (g_file_mount_mountable), (g_file_unmount_mountable),

View File

@ -261,8 +261,7 @@ match_prefix (const char *path,
}
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 @@ g_dummy_file_file_iface_init (GFileIface *iface)
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;

View File

@ -617,32 +617,60 @@ g_file_get_child_for_display_name (GFile *file,
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);
}
/**

View File

@ -187,7 +187,7 @@ typedef gboolean (* GFileReadMoreCallback) (const char *file_contents,
* @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 @@ struct _GFileIface
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 (GFile
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,

View File

@ -230,7 +230,7 @@ g_file_get_parse_name
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

View File

@ -519,8 +519,8 @@ match_prefix (const char *path,
}
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 @@ g_local_file_file_iface_init (GFileIface *iface)
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;

View File

@ -348,12 +348,12 @@ test_g_file_new_for_commandline_arg (void)
}
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 @@ get_relative_path (const gboolean use_uri, const gboolean should_contain_file, c
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 @@ get_relative_path (const gboolean use_uri, const gboolean should_contain_file, c
}
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 @@ main (int argc,
/* 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);