gnome_vfs_file_info_matches patch - 3
- From: Mathieu Lacage <mathieu_lacage myrealbox com>
- To: Alexander Larsson <alexl redhat com>
- Cc: gnome-vfs-list gnome org
- Subject: gnome_vfs_file_info_matches patch - 3
- Date: Thu, 18 Sep 2003 09:06:26 +0200
bwaaah.
Because I did doubt of my ability to write a correct patch with all the
code in one function, I added two helper match functions. At least, now,
when I read this code, I don't get headaches.
It might be worth doing the same for the name field thus protecting the
function against NULL parameters but I think it was not designed to be
protected against such occurences.
Mathieu
On Wed, 2003-09-17 at 15:10, Alexander Larsson wrote:
> On Wed, 2003-09-17 at 13:50, Mathieu Lacage wrote:
> > hi,
> >
> > Here is a revised version of the patch. As before, extensively tested,
> > seems to work fine.
>
>
> if (a->mime_type == NULL || b->mime_type == NULL) {
> return a->mime_type == b->mime_type;
> }
> -
> g_assert (a->mime_type != NULL && b->mime_type != NULL);
> - return g_ascii_strcasecmp (a->mime_type, b->mime_type) == 0;
> +
> + if (a->symlink_name == NULL || b->symlink_name == NULL) {
> + return a->symlink_name == b->symlink_name;
> + }
> + g_assert (a->symlink_name != NULL && b->symlink_name != NULL);
> +
> + if (g_ascii_strcasecmp (a->mime_type, b->mime_type) == 0
> + && strcmp (a->symlink_name, b->symlink_name) == 0) {
> + return TRUE;
> + } else {
> + return FALSE;
> + }
> }
>
> This isn't right, you can't go on returning a == b all the time. What if
> a->mimetype and b->mimetype is both NULL, but the symlink name is
> different?
>
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Alexander Larsson Red Hat, Inc
> alexl redhat com alla lysator liu se
> He's a time-tossed one-eyed gangster who hangs with the wrong crowd. She's a
> brilliant thirtysomething advertising executive prone to fits of savage,
> blood-crazed rage. They fight crime!
>
> _______________________________________________
> gnome-vfs-list mailing list
> gnome-vfs-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-vfs-list
--
Mathieu Lacage <mathieu gnu org>
? patch
? stamp-h1
? doc/gnome-vfs-2.0-decl-list.txt
? doc/gnome-vfs-2.0-decl.txt
? doc/gnome-vfs-2.0-undocumented.txt
? doc/gnome-vfs-2.0-unused.txt
? doc/gnome-vfs-2.0.args
? doc/gnome-vfs-2.0.hierarchy
? doc/gnome-vfs-2.0.signals
? doc/xml
? doc/tmpl/gnome-vfs-2.0-unused.sgml
? doc/tmpl/gnome-vfs.sgml
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-vfs/ChangeLog,v
retrieving revision 1.1614
diff -u -r1.1614 ChangeLog
--- ChangeLog 17 Sep 2003 09:11:02 -0000 1.1614
+++ ChangeLog 18 Sep 2003 06:57:30 -0000
@@ -1,3 +1,10 @@
+2003-09-11 Mathieu Lacage <mathieu gnome org>
+
+ * libgnomevfs/gnome-vfs-file-info.c: make gnome_vfs_file_info_matches
+ match against everything in the FileInfo structure. This effectively makes
+ this function behave like an _equals function but we cannot change the
+ name of the function.
+
2003-09-17 Alexander Larsson <alexl redhat com>
* libgnomevfs/gnome-vfs-async-job-map.c (_gnome_vfs_async_job_map_get_job):
Index: libgnomevfs/gnome-vfs-file-info.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-file-info.c,v
retrieving revision 1.22
diff -u -r1.22 gnome-vfs-file-info.c
--- libgnomevfs/gnome-vfs-file-info.c 18 Dec 2002 16:40:00 -0000 1.22
+++ libgnomevfs/gnome-vfs-file-info.c 18 Sep 2003 06:57:30 -0000
@@ -212,12 +212,41 @@
}
+static gboolean
+mime_matches (char *a, char *b)
+{
+ if (a == NULL && b == NULL) {
+ return TRUE;
+ } else if ((a != NULL && b == NULL) ||
+ (a == NULL && b != NULL)) {
+ return FALSE;
+ } else {
+ g_assert (a != NULL && b != NULL);
+ return g_ascii_strcasecmp (a, b) == 0;
+ }
+}
+
+static gboolean
+symlink_name_matches (char *a, char *b)
+{
+ if (a == NULL && b == NULL) {
+ return TRUE;
+ } else if ((a != NULL && b == NULL) ||
+ (a == NULL && b != NULL)) {
+ return FALSE;
+ } else {
+ g_assert (a != NULL && b != NULL);
+ return strcmp (a, b) == 0;
+ }
+}
+
/**
* gnome_vfs_file_info_matches
* @a: first GnomeVFSFileInfo struct to compare
* @b: second GnomeVFSFileInfo struct to compare
*
- * Compare the two file info structs, return TRUE if they match.
+ * Compare the two file info structs, return TRUE if they match exactly
+ * the same file data.
*
* Returns: TRUE if the two GnomeVFSFileInfos match, otherwise return FALSE.
**/
@@ -230,22 +259,34 @@
g_return_val_if_fail (a->name != NULL, FALSE);
g_return_val_if_fail (b->name != NULL, FALSE);
+ /* This block of code assumes that the GnomeVfsFileInfo
+ was correctly allocated with g_new0 which means that each pair
+ of fields are either invalid and equal to NULL or are valid
+ If both GnomeVfsFileInfos have only invalid fields, the
+ function returns TRUE. That is, it says the infos match which is,
+ in a sense, true :)
+ */
+
if (a->type != b->type
|| a->size != b->size
|| a->block_count != b->block_count
|| a->atime != b->atime
|| a->mtime != b->mtime
|| a->ctime != b->ctime
- || strcmp (a->name, b->name) != 0) {
+ || a->flags != b->flags
+ || a->permissions != b->permissions
+ || a->device != b->device
+ || a->inode != b->inode
+ || a->link_count != b->link_count
+ || a->uid != b->uid
+ || a->gid != b->gid
+ || strcmp (a->name, b->name) != 0
+ || !mime_matches (a->mime_type, b->mime_type)
+ || !symlink_name_matches (a->mime_type, b->mime_type)) {
return FALSE;
+ } else {
+ return TRUE;
}
-
- if (a->mime_type == NULL || b->mime_type == NULL) {
- return a->mime_type == b->mime_type;
- }
-
- g_assert (a->mime_type != NULL && b->mime_type != NULL);
- return g_ascii_strcasecmp (a->mime_type, b->mime_type) == 0;
}
/**
Index: libgnomevfs/gnome-vfs-file-info.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-file-info.h,v
retrieving revision 1.26
diff -u -r1.26 gnome-vfs-file-info.h
--- libgnomevfs/gnome-vfs-file-info.h 18 Dec 2002 16:40:00 -0000 1.26
+++ libgnomevfs/gnome-vfs-file-info.h 18 Sep 2003 06:57:31 -0000
@@ -234,7 +234,7 @@
link points to. */
char *symlink_name;
- /* MIME type. */
+ /* MIME type. -- ascii string */
char *mime_type;
guint refcount;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]