2 Disabling of filecheck is not actually possible because btw it cause the attachment.pm to malfunction and
3 any of pagespec that could contain a *mimetype* condition.
5 attachment.pm imports "statically" filecheck so actually disabling it should be *interdicted* .
9 add_underlay("attachment");
10 add_underlay("javascript");
11 add_underlay("jquery");
12 hook(type => "getsetup", id => "attachment", call => \&getsetup);
13 hook(type => "checkconfig", id => "attachment", call => \&checkconfig);
14 hook(type => "formbuilder_setup", id => "attachment", call => \&formbuilder_setup);
15 hook(type => "formbuilder", id => "attachment", call => \&formbuilder, last => 1);
16 IkiWiki::loadplugin("filecheck");
24 So I tried on three pages to inline <tt>!mimetype(image/*)</tt> while I allowed attachment of <tt>mimetype(image/*)</tt>
26 My profiling tests in the bug report shows that most of the time is spend in the "Fallback using file" block code,
27 I tried to comment that block and see how it'll perform. Obviously this is much much faster ... but is the mimetype
28 discovered using only *File::MimeInfo* ?
31 Dumping some strings before return to STDERR, rebuilding . This is just a [[!toggle id="code-test" text="dumpdebug adding"]]
33 [[!toggleable id="code-test" text="""
35 sub match_mimetype ($$;@) {
40 my $file=exists $params{file} ? $params{file} : IkiWiki::srcfile($IkiWiki::pagesources{$page});
41 if (! defined $file) {
42 return IkiWiki::ErrorReason->new("file does not exist");
47 # First, try File::Mimeinfo. This is fast, but doesn't recognise
49 eval q{use File::MimeInfo::Magic};
52 print STDERR " --- match_mimetype (".$file.")\n";
54 my $mimetype=File::MimeInfo::Magic::magic($file);
57 # Fall back to using file, which has a more complete
59 #if (! defined $mimetype) {
60 # open(my $file_h, "-|", "file", "-bi", $file);
61 # $mimetype=<$file_h>;
66 if (! defined $mimetype || $mimetype !~s /;.*//) {
67 # Fall back to default value.
68 $mimetype=File::MimeInfo::Magic::default($file)
70 if (! defined $mimetype) {
75 my $regexp=IkiWiki::glob2re($wanted);
76 if ($mimetype!~$regexp) {
77 print STDERR " xxx MIME unknown ($mimetype - $wanted - $regexp ) \n";
78 return IkiWiki::FailReason->new("file MIME type is $mimetype, not $wanted");
81 print STDERR " vvv MIME found\n";
82 return IkiWiki::SuccessReason->new("file MIME type is $mimetype");
88 The results dump to stderr (or a file called... 'say *mime*) looks like this :
90 --- match_mimetype (/usr/share/ikiwiki/attachment/ikiwiki/jquery.fileupload-ui.js)
91 xxx MIME unknown (text/plain - image/* - (?i-xsm:^image\/.*$) )
92 --- match_mimetype (/usr/share/ikiwiki/locale/fr/directives/ikiwiki/directive/fortune.mdwn)
93 xxx MIME unknown (text/plain - image/* - (?i-xsm:^image\/.*$) )
94 --- match_mimetype (/usr/share/ikiwiki/locale/fr/basewiki/shortcuts.mdwn)
95 xxx MIME unknown (text/plain - image/* - (?i-xsm:^image\/.*$)
96 --- match_mimetype (/usr/share/ikiwiki/smiley/smileys/alert.png)
97 xxx MIME unknown (application/octet-stream - image/* - (?i-xsm:^image\/.*$) )
98 --- match_mimetype (/usr/share/ikiwiki/attachment/ikiwiki/images/ui-bg_flat_75_ffffff_40x100.png)
99 xxx MIME unknown (application/octet-stream - image/* - (?i-xsm:^image\/.*$)
102 <tt>---</tt> prepend signals the file on analysis<br/>
103 <tt>xxx</tt> prepend signals a returns failure : mime is unknown, the match is a failure<br/>
104 <tt>vvv</tt> prepend signals a return success.<br/>
107 This is nasty-scary results ! Something missed me or this mime-filecheck is plain nuts ?
109 *Question 1* : How many files have been analysed : **3055** (yet on a tiny tiny wiki)
110 <pre>grep "^ --- " mime | wc -l
114 *Question 2* : How many time it fails : *all the time*
116 grep "^ xxx " mime | wc -l
120 *Question 1bis* : Doh btw , how many files have been re-analysed ? ** 2835 ** OMG !!
121 <pre>grep "^ --- " mime | sort -u | wc -l
127 - Only the system command *file -bi* works. While it is **should** be easy on the cpu , it's also hard on the I/O -> VM :(
128 - Something nasty with the mime implementation and/or my system configuration -> Hints ? :D
129 - Need to cache during the rebuild : a same page needs not being rechecked for its mime while it's locked !
134 > > if ($mimeinfo_ok) {
135 > > my $mimetype=File::MimeInfo::Magic::magic($file);
138 > That seems strange to me, `my` restricts scope of $mimetype to enclosing if block, thus, assigned value will be dropped - I think, it is the problem.
139 > Try removing that stray `my`.