nemo r95 - trunk/metadata



Author: arj
Date: Mon Mar 10 17:46:05 2008
New Revision: 95
URL: http://svn.gnome.org/viewvc/nemo?rev=95&view=rev

Log:
Fix two bugs in indexing

- If watch_dir in config ends with / it would try to insert all files
  in the top level directory on reindex
- Fix deleting and reinserting files + labels when indexing. The
  problem was that the sorting order of sqlite3 was different from
  .Net.



Modified:
   trunk/metadata/MetadataStore.cs

Modified: trunk/metadata/MetadataStore.cs
==============================================================================
--- trunk/metadata/MetadataStore.cs	(original)
+++ trunk/metadata/MetadataStore.cs	Mon Mar 10 17:46:05 2008
@@ -6,6 +6,7 @@
 using System.Text;
 using Mono.Data.Sqlite;
 using System.Text.RegularExpressions;
+using System.Diagnostics;
 
 namespace Nemo 
 {
@@ -769,9 +770,43 @@
 			}
         }
 
+		public static int Sqlite3Sort(string a, string b) 
+		{
+			int y, z;
+				
+			for (int i = 0; i < a.Length; ++i)
+			{
+				if (a[i].Equals(b[i])) continue;
+
+				bool w = Int32.TryParse(a.Substring(i, 1), out y), x = Int32.TryParse(b.Substring(i, 1), out z);
+				bool bothNumbers = w && x, bothNotNumbers = !w && !x;
+
+				if (bothNumbers) 
+					return y.CompareTo(z);
+				else if (bothNotNumbers) 
+					return a[i].CompareTo(b[i]);
+				else if (w) {
+					if (b[i] == '.')
+						return 1;
+					else
+						return -1;
+				} else {
+					if (a[i] == '.')
+						return -1;
+					else
+						return 1;
+				}
+			}
+				
+			return 0;
+		} 
+		
 		// returns how many was inserted
 		private IEnumerable<int> db_sync_directory_with_filesystem(string directory_path)
         {
+			if (directory_path.EndsWith("/"))
+				directory_path = directory_path.Substring(0, directory_path.Length-1);
+			
             // get filesystem files and database files
             string[] files = new string[0];
             try {
@@ -786,7 +821,7 @@
             	if (filename_is_good(file))
             		fsfiles.Add(file);
             
-            fsfiles.Sort();
+            fsfiles.Sort(Sqlite3Sort);
             
 			List<string> dbfiles = database.get_file_paths_in_directory(directory_path);
 
@@ -826,6 +861,8 @@
                 moredb = idb.MoveNext();
             }
 			
+			System.Console.WriteLine("checking path {0}: added {1}, deleted {2}, updated {3}", directory_path, add_files.Count, delete_files.Count, update_files.Count);			
+			
 			bool inserted = delete_files.Count > 0 || add_files.Count > 0 || update_files.Count > 0;
 
 			int nr_changes = 0;
@@ -1280,6 +1317,8 @@
 
         public List<string> get_file_paths_in_directory(string directory_path)
         {
+			Debug.Assert(!directory_path.EndsWith("/"));
+			
             using (IDbCommand cmd = get_command()) {
 				cmd.CommandText = String.Format("select path from files where path like \"{0}{1}%\" and path not like \"{0}{1}%{1}%\" order by path", directory_path, Path.DirectorySeparatorChar);
 



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