]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/filecheck_failing_to_find_files.mdwn
e896f2129d603e88b9667136d14ac1c1e4914962
[ikiwiki.git] / doc / bugs / filecheck_failing_to_find_files.mdwn
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!)
2
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.
4
5 > I don't understand why the file was not in `%pagesources`. Do you?
6 > --[[Joey]]
7
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]]
12
13 >>> Ok, so it's not removal specific, can in fact be triggered by using
14 >>> testpagespec (or really anything besides attachment, which passes
15 >>> the filename parameter). Nor is it limited to mimetype, all the tests in 
16 >>> filecheck have the problem. [[Fixed|done]] --[[Joey]] 
17
18 The following patch fixes the problem:
19
20         diff --git a/IkiWiki/Plugin/filecheck.pm b/IkiWiki/Plugin/filecheck.pm
21         index 01d4909..1cec0cf 100644
22         --- a/IkiWiki/Plugin/filecheck.pm
23         +++ b/IkiWiki/Plugin/filecheck.pm
24         @@ -118,6 +118,10 @@ sub match_mimetype ($$;@) {
25                 if (! defined $file) {
26                         return IkiWiki::ErrorReason->new("no file specified");
27                 }
28         +       if (! -e $file) {
29         +           # get the absolute path of the file if you can't find it
30         +           $file = IkiWiki::srcfile($file);
31         +       }
32          
33                 # Use ::magic to get the mime type, the idea is to only trust
34                 # data obtained by examining the actual file contents.