Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Issue with fileutil::magic::filetype

44 views
Skip to first unread message

Kevin Walzer

unread,
Apr 24, 2018, 7:57:27 AM4/24/18
to
After installing Tcllib 1.9, I run this script:

package require fileutil::magic::filetype
fileutil::magic::filetype /Users/kevin/Desktop/dndtest.rb

Based on inspection of the source code of the module, I expect the
output to be something like:

mime text/x-ruby

but there's no output at all.

Checking to see if the module is correctly installed, I run this command:

fileutil::magic::filetype
/Users/kevin/Downloads/tcllib-1.19/devdoc/devguide.html

And I get this output:

{{HTML document text}} {text html} {}

So, it seems to be working as designed, at least in this instance.

My use case for this module is to glob a directory and return a list of
files of type "text," to filter out anything that can't be read and
displayed in the text widget. Ruby has a module that does this quite
well, but the particular app here is written in Tcl. However, the silent
failure of the module in some instances gives me pause.

Am I doing something wrong, or is there a bug in this library?

--Kevin

--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com

Kevin Walzer

unread,
Apr 24, 2018, 7:57:27 AM4/24/18
to

stefan

unread,
Apr 26, 2018, 5:30:58 AM4/26/18
to
To me, it seems that the recognition patterns sourced from the file/magic database are desperately outdated (2005!). And the the Ruby regexp patterns from that time are just too limited or just broken (e.g., they seem to check for block ends at the same line as the block starters etc.)

Unless your Ruby file reads like "class X end" or "module X end" or starts with a shebang, fileutil won't recognise it at all.

More up-to-date magic databases are much more elaborated, e.g.,
https://github.com/file/file/blob/master/magic/Magdir/ruby

So one will have to file a ticket and regenerate fileutil's filetypes.tcl from a modern magic db.

HTH,
Stefan



stefan

unread,
Apr 26, 2018, 6:03:01 AM4/26/18
to

> Unless your Ruby file reads like "class X end" or "module X end" or starts with a shebang, fileutil won't recognise it at all.

It is worse than expected, a file with content:

class A
def x
end
end

will fail (like anything else) with the following regexp check (fileutil debug output):


String '^[ ]*end([ ]*[;#].*)?$' eq 'class A
def x
end
end
' - 0

This can't work.
//s
0 new messages