1 Using the attachment plugin, when filecheck was checking the mime-type of the attachment before allowing the attachment to be removed, it was returning with an error saying that the mime-type of the file was "unknown" (when the mime-type definitely was known!)
3 It turns out that the filecheck plugin couldn't find the file, because it was merely using the $pagesources hash, rather than finding the absolute path of the file in question.
5 > I don't understand why the file was not in `%pagesources`. Do you?
8 >> The file *was* in `%pagesources`, but what returns from that is the filename relative to the `srcdir` directory; for example, `foo/bar.gif`.
9 >> When File::MimeInfo::Magic::magic is given that, it can't find the file.
10 >> But if it is given `/path/to/srcdir/foo/bar.gif` instead, then it *can* find the file, and returns the mime-type correctly.
11 >> --[[KathrynAndersen]]
13 The following patch fixes the problem:
15 diff --git a/IkiWiki/Plugin/filecheck.pm b/IkiWiki/Plugin/filecheck.pm
16 index 01d4909..1cec0cf 100644
17 --- a/IkiWiki/Plugin/filecheck.pm
18 +++ b/IkiWiki/Plugin/filecheck.pm
19 @@ -118,6 +118,10 @@ sub match_mimetype ($$;@) {
20 if (! defined $file) {
21 return IkiWiki::ErrorReason->new("no file specified");
24 + # get the absolute path of the file if you can't find it
25 + $file = IkiWiki::srcfile($file);
28 # Use ::magic to get the mime type, the idea is to only trust
29 # data obtained by examining the actual file contents.