Sanitize paths before we add them as roots. Index: ChangeLog =================================================================== RCS file: /cvs/gnome/beagle/ChangeLog,v retrieving revision 1.215 diff -u -B -p -r1.215 ChangeLog --- ChangeLog 12 Aug 2005 18:35:55 -0000 1.215 +++ ChangeLog 12 Aug 2005 20:15:33 -0000 @@ -3,7 +3,10 @@ * beagled/FileSystemQueryable/FileNameFilter.cs, beagled/FileSystemQueryable/FileSystemQueryable.cs: Drop internal directory references when we add an exclude path. Also forget inotify - watches. + watches. Sanitize paths before we add them as roots. + + * Util/StringFu.cs: Add SanitizePath, which trims excess leading and + trailing slashes. 2005-08-11 Veerapuram Varadhan Index: Util/StringFu.cs =================================================================== RCS file: /cvs/gnome/beagle/Util/StringFu.cs,v retrieving revision 1.29 diff -u -B -p -r1.29 StringFu.cs --- Util/StringFu.cs 10 Aug 2005 19:41:18 -0000 1.29 +++ Util/StringFu.cs 12 Aug 2005 20:15:34 -0000 @@ -484,6 +484,23 @@ namespace Beagle.Util { return CountWords (str, -1); } + // Strip trailing slashes and make sure we only have 1 leading slash + static public string SanitizePath (string path) + { + if (path.StartsWith ("//")) { + int pos; + for (pos = 2; pos < path.Length; pos++) + if (path [pos] != '/') + break; + + path = path.Substring (pos - 1); + } + if (!(path.Length == 1 && path [0] == '/')) + path = path.TrimEnd ('/'); + + return path; + } + static void Main (string [] args) { foreach (string arg in args) Index: beagled/FileSystemQueryable/DirectoryModel.cs =================================================================== RCS file: /cvs/gnome/beagle/beagled/FileSystemQueryable/DirectoryModel.cs,v retrieving revision 1.4 diff -u -B -p -r1.4 DirectoryModel.cs --- beagled/FileSystemQueryable/DirectoryModel.cs 11 Aug 2005 22:33:47 -0000 1.4 +++ beagled/FileSystemQueryable/DirectoryModel.cs 12 Aug 2005 20:15:35 -0000 @@ -80,22 +80,9 @@ namespace Beagle.Daemon.FileSystemQuerya /////////////////////////////////////////////////////////// - static private string StripTrailingSlashes (string path) - { - if (path == null) - return null; - - while (path.Length > 0 && path [path.Length-1] == System.IO.Path.DirectorySeparatorChar) - path = path.Substring (0, path.Length-1); - - return path; - } - - /////////////////////////////////////////////////////////// - static public DirectoryModel NewRoot (object big_lock, string path, FileAttributes attr) { - path = StripTrailingSlashes (path); + path = StringFu.SanitizePath (path); DirectoryModel root; root = new DirectoryModel (attr); @@ -394,7 +381,7 @@ namespace Beagle.Daemon.FileSystemQuerya { lock (big_lock) { - path = StripTrailingSlashes (path); + path = StringFu.SanitizePath (path); if (IsRoot) { Index: beagled/FileSystemQueryable/FileSystemQueryable.cs =================================================================== RCS file: /cvs/gnome/beagle/beagled/FileSystemQueryable/FileSystemQueryable.cs,v retrieving revision 1.71 diff -u -B -p -r1.71 FileSystemQueryable.cs --- beagled/FileSystemQueryable/FileSystemQueryable.cs 12 Aug 2005 18:35:56 -0000 1.71 +++ beagled/FileSystemQueryable/FileSystemQueryable.cs 12 Aug 2005 20:15:37 -0000 @@ -418,6 +418,7 @@ namespace Beagle.Daemon.FileSystemQuerya public void AddRoot (string path) { + path = StringFu.SanitizePath (path); Logger.Log.Debug ("Adding root: {0}", path); if (roots_by_path.Contains (path)) {