Re: Suggestion for file type detection approach

On Thu, 2003-12-25 at 19:58, Adam Williams wrote:
> > I've spent some time today thinking about the costs and benefits of the
> > two approaches used today in GNOME to determine the MIME Type of a file.
> > Also, I've done some experiments and tweakings to check the impact that 
> > file sniffing has over nautilus performance. It's impressive. See below.
> Why not support recording the mime-type of a file as meta-data (EA) on
> filesystems that support it (every one of them at this point?).  It
> would take awhile to be adopted by most/all GNOME apps but seems (IMHO)
> to clearly be the right way to do it.   If GNOME VFS supported it then
> it seems it would be easy to implement for alot of applications.
> File extenstions are just DUMB and EASILY broken.  Sniffing is expensive
> and unreliable.

Actually getting the MIME type to store in the EA isn't exactly easy or
safe, either.  Many, many files come from sources that don't provide
MIME types (tar, ftp, etc.), while other sources may lie about the MIME
type (a lot of web servers have a habit of reporting RPM files with a
bogus, non-existent MIME type, or a completely wrong one altogether -
because they use suffix sniffing and hacked up file type databases).

Assuming the content sniffer is intelligent, it will always be correct. 
If a file is a PNG, it'll always be in PNG format.  If the file is a
StarOffice document, it'll always be in the SO format.  If the content
sniffer is just looking at a few bytes in the beginning, then sure, it
could get it wrong...

Using several techniques together might make for the most ideal user
experience, tho it'll probably be complicated on the code end.  For
example, if a local filesystem has a MIME EA, use that, otherwise, use a
suffix check.  Doing a JIT file content check (i.e., right when you open
the file) could offer an additional layer of security, without requiring
wasting lots of time.  When opening the file, Nautilus could present
some kind of dialog if the content sniff doesn't match what Nautilus
thought the file was ("The file '' is a BAR file, but is
misidentified as a FOO file.  Nautilus can correct the file suffix/type
for you.  [Cancel] [Correct File Type] [Correct and Open]").

> _______________________________________________
> gnome-devel-list mailing list
> gnome-devel-list gnome org
Sean Middleditch <elanthis awesomeplay com>
AwesomePlay Productions, Inc.

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