[gnome-utils/gnome-2-26] Fix gio inode and device handling for hardlinks



commit 5014bb4d81a24586be00c35e57436bee4833abfa
Author: Paolo Borelli <porelli gnome org>
Date:   Sun Jun 28 13:30:04 2009 +0200

    Fix gio inode and device handling for hardlinks

 baobab/src/baobab-scan.c |   39 +++++++++++++++++++++++++--------------
 1 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/baobab/src/baobab-scan.c b/baobab/src/baobab-scan.c
index 35e88d8..3c33352 100644
--- a/baobab/src/baobab-scan.c
+++ b/baobab/src/baobab-scan.c
@@ -67,8 +67,8 @@ baobab_hardlinks_array_create (void)
 }
 
 static gboolean
-baobab_hardlinks_array_has (BaobabHardLinkArray   *a,
-			    GFileInfo  		  *s)
+baobab_hardlinks_array_has (BaobabHardLinkArray *a,
+			    BaobabHardLink      *s)
 {
 	guint i;
 
@@ -79,10 +79,7 @@ baobab_hardlinks_array_has (BaobabHardLinkArray   *a,
 		 * cur->st_dev == s->st_dev is the common case and may be more
 		 * expansive than cur->st_ino == s->st_ino
 		 * so keep this order */
-		if (cur->inode == g_file_info_get_attribute_uint64 (s,
-							G_FILE_ATTRIBUTE_UNIX_INODE) &&
-		    cur->device == g_file_info_get_attribute_uint32 (s,
-							G_FILE_ATTRIBUTE_UNIX_DEVICE))
+		if (cur->inode == s->inode && cur->device == s->device)
 			return TRUE;
 	}
 
@@ -92,20 +89,32 @@ baobab_hardlinks_array_has (BaobabHardLinkArray   *a,
 /* return FALSE if the element was already in the array */
 static gboolean
 baobab_hardlinks_array_add (BaobabHardLinkArray *a,
-			    GFileInfo    *s)
+			    GFileInfo           *s)
 {
-	BaobabHardLink hl;
 
-	if (baobab_hardlinks_array_has (a, s))
-		return FALSE;
+	if (g_file_info_has_attribute (s, G_FILE_ATTRIBUTE_UNIX_INODE) &&
+	    g_file_info_has_attribute (s, G_FILE_ATTRIBUTE_UNIX_DEVICE))
+	{
+		BaobabHardLink hl;
 
-	hl.inode = g_file_info_get_attribute_uint64 (s,
+		hl.inode = g_file_info_get_attribute_uint64 (s,
 				G_FILE_ATTRIBUTE_UNIX_INODE);
-	hl.device = g_file_info_get_attribute_uint32 (s,
+		hl.device = g_file_info_get_attribute_uint32 (s,
 				G_FILE_ATTRIBUTE_UNIX_DEVICE);
-	g_array_append_val (a, hl);
 
-	return TRUE;
+		if (baobab_hardlinks_array_has (a, s))
+			return FALSE;
+
+		g_array_append_val (a, hl);
+
+		return TRUE;
+	}
+	else
+	{
+		g_warning ("Could not obtain inode and device for hardlink");
+	}
+
+	return FALSE;
 }
 
 static void
@@ -131,6 +140,8 @@ static const char *dir_attributes = \
 	G_FILE_ATTRIBUTE_STANDARD_SIZE "," \
 	G_FILE_ATTRIBUTE_UNIX_BLOCKS "," \
 	G_FILE_ATTRIBUTE_UNIX_NLINK "," \
+	G_FILE_ATTRIBUTE_UNIX_INODE "," \
+	G_FILE_ATTRIBUTE_UNIX_DEVICE "," \
 	G_FILE_ATTRIBUTE_ACCESS_CAN_READ;
 
 



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