GNOME Bugzilla – Bug 170437
[PATCH] Beagle does not index filenames containing "\".
Last modified: 2005-04-05 05:47:56 UTC
Please describe the problem: Steps to reproduce: 1. Create a text file with a name that contains a "\" char. 2. Try to index it with beagle 3. Actual results: Beagle throws the following exception: DEBUG: *** What should we do with /home/varadhan/samples/beagle's\ test.txt? DEBUG: *** No attributes on /home/varadhan/samples/beagle's\ test.txt ERROR: Caught exception inside Inotify.Event ERROR: System.NullReferenceException: Object reference not set to an instance of an object in [0x0004d] (at /home/varadhan/work/cvs/beagle-cvs/beagle/beagled/FileSystemQueryable/FileSystemModel.cs:954) Beagle.Daemon.FileSystemQueryable.FileSystemModel:PathToUid (string) in [0x00002] (at /home/varadhan/work/cvs/beagle-cvs/beagle/beagled/FileSystemQueryable/FileSystemModel.cs:962) Beagle.Daemon.FileSystemQueryable.FileSystemModel:PathToInternalUri (string) in [0x00007] (at /home/varadhan/work/cvs/beagle-cvs/beagle/beagled/FileSystemQueryable/FileSystemModel.cs:967) Beagle.Daemon.FileSystemQueryable.FileSystemModel:ToInternalUri (System.Uri) in [0x00034] (at /home/varadhan/work/cvs/beagle-cvs/beagle/beagled/FileSystemQueryable/FileSystemQueryable.cs:114) Beagle.Daemon.FileSystemQueryable.FileSystemQueryable:Add (string) in [0x00201] (at /home/varadhan/work/cvs/beagle-cvs/beagle/beagled/FileSystemQueryable/InotifyBackend.cs:173) Beagle.Daemon.FileSystemQueryable.InotifyBackend:OnInotifyEvent (int,string,string,string,Beagle.Util.Inotify/EventType) in <0x00057> (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_int_string_string_string_Inotify/EventType (int,string,string,string,Beagle.Util.Inotify/EventType) in <0x00034> (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_int_string_string_string_Inotify/EventType (int,string,string,string,Beagle.Util.Inotify/EventType) in [0x000a7] (at /home/varadhan/work/cvs/beagle-cvs/beagle/Util/Inotify.cs:471) Beagle.Util.Inotify:SendEvent (Beagle.Util.Inotify/Watched,string,string,Beagle.Util.Inotify/EventType) Expected results: Beagle should index the file Does this happen every time? Yes Other information:
Fix is in my local tree. Will attach the patch soon.
Created attachment 38767 [details] [review] Part-1 fix
Jon: Here are my findings.... The core of the problem is '\' character. '\' and '/' are treated same in MS Windows and so are .NET libraries (atleast IMHO). So, essentially, /home/foo/bar\file.txt == /home/foo/bar/file.txt in Windows but not in Linux. The fix for this bug contains two parts. Part 1:- PathToQuotedFileUri (): The path passed to this method as an argument should be properly escaped before calling Path.GetFullPath() which screwes up the '\' and '/' handling, according to Linux. Fix for part 1:- see the attachment, "Part-1 fix". Part 2:- FileInfo class: This class also doesn't understand the difference between '\' and '/' in Linux. When, from FilteredIndexable.BuildFromFile(), Filter.Open (new FileInfo (path)) gets called, the original path, "/home/foo/bar\file.txt" gets converted to "/home/foo/bar/file.txt" and thus generating the "FileNotFoundException". Fix for part 2:- FileStream class can be used instead of FileInfo. A basic study on the usage of FileInfo in Filters reveal that only FullName and Length properties of FileInfo class were being used. FileStream also has Length and Name properties that return same values that of FileInfo class. However, a small difference do exist between FileInfo.FullName and FileStream.Name, FileStream.Name will not give "fully-qualified-path", but, beagle already generates the fully-qualified-path before giving it to filters. (see, Part-1, PathToQuotedFileUri.
Ok. Enough investigation is done. This seems to be a limitation in Mono. Mono treats both '\' and '/' as path separators and which is the source of this bug. I did a simple investigation in java using the following sample code, which seems to work fine. import java.io.*; public class javapath { public static void main (String[] args) { File f = new File (args[0]); System.out.println ("getname: "+f.getName()); System.out.println ("getpath: "+f.getPath()); System.out.println ("getAbsolutePath: "+f.getAbsolutePath()); } } and the output is.. varadhan@linux:~/tries> java javapath /home/varadhan/samples/beagle\'s\\\ test.txt getname: beagle's\ test.txt getpath: /home/varadhan/samples/beagle's\ test.txt getAbsolutePath: /home/varadhan/samples/beagle's\ test.txt ---------------- FileStream class however, is able to handle these files properly, but only when you "open" an existing file. Will add more comments/findings later.
This is a mono bug. See http://bugzilla.ximian.com/show_bug.cgi?id=68566 and http://bugzilla.ximian.com/show_bug.cgi?id=71214
Created attachment 38903 [details] [review] Handle '\' cases.
Created attachment 38904 [details] [review] Handle '\' cases properly and do not spew out exception traces.
Comment on attachment 38903 [details] [review] Handle '\' cases. Handle '\' cases properly and do not spew out exception traces.
Tested this, works fine as a workaround for me.
Thanks for sending in. Raising priority to make maintainers aware of patch. Adding PATCH keyword.
*** Bug 172244 has been marked as a duplicate of this bug. ***
Fixed in CVS.