ikiwiki/doc/bugs/attachment:_failed_to_get_f...

116 lines
5.2 KiB
Plaintext
Raw Normal View History

I can't add any attachment to my wiki. When I select file using "Browse"
button and click "Upload Attachment", then `ikiwiki.cgi` file displays
the error message like below:
Błąd: failed to get filehandle
2008-07-08 15:46:29 +02:00
> Can you do some debugging? If you edit attachment.pm line 136, to print
> out what it did get, and show me what that yields, maybe I can figure
> this out.
error("failed to get filehandle ($fh)");
>> Sure. I've done the change and it seems that $fh variable is undefined:
>> Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/IkiWiki/Plugin/attachment.pm line 135.
>> failed to get filehandle ()
2008-07-08 15:46:29 +02:00
> Also, what web server and version of perl is this? --[[Joey]]
>> It's Apache2 2.2.8-1ubuntu0.3 and Perl 5.8.8-12 from Ubuntu Hardy. --[[Paweł|ptecza]]
2008-07-08 16:16:29 +02:00
>>> Hmm, is your CGI.pm perhaps creating the attachment temp file, but
>>> not providing an open filehandle to it via the `upload` method?
>>> Change the debugging line to this: --[[Joey]]
error("failed to get filehandle:$fh ; file:$filename ; is ref:".ref($q->param('attachment')));
>>>> Now my Ikiwiki returns:
>>>> failed to get filehandle: ; file:sandbox/test.txt ; is ref:
>>>> Is it helpful for you? --[[Paweł|ptecza]]
2008-07-08 16:43:45 +02:00
>>>>> Yes, this suggests that CGI.pm's `upload` function is not working,
>>>>> but that it *is* returning a filehandle pointing at the attachment
>>>>> using the old method. Hmm, so I'll bet you have a CGI.pm version
>>>>> older than 2.47. Can you find your system's CGI.pm and grep for
>>>>> "VERSION" in it to determine the version? I checked debian stable.
>>>>> and its perl 5.8.8 has version 3.15, so is not affected, I think.
>>>>>> I have CGI.pm 3.15 too:
>>>>>> $ grep VERSION= /usr/share/perl/5.8.8/CGI.pm
>>>>>> $CGI::VERSION='3.15';
2008-07-08 16:43:45 +02:00
>>>>> I've just checked in a fix that should work, can you test it?
>>>>> [diff](http://git.ikiwiki.info/?p=ikiwiki;a=commitdiff;h=71f10579c00a8ddc20ada1a1efd33aac25a3da7e) --[[Joey]]
>>>>>> I've patched `attachment.pm` module, but the bug still occurs.
>>>>>> However I can see a little progress. I changed invoking `error()`
>>>>>> subroutine like you showed me before and now Ikiwiki prints
>>>>>> failed to get filehandle:test.txt ; file:sandbox/test.txt ; is ref:
>>>>>> --[[Paweł|ptecza]]
>>>>>>> Well then, your CGI.pm is somehow not behaving as its documentation
>>>>>>> describes, in two ways:
>>>>>>> 1. `upload()` is not returning a reference to the filehandle
>>>>>>> 2. The filename returned by `param("attachment")` is not also
>>>>>>> a file handle.
>>>>>>> That seems very broken. I can try to work around it some more
>>>>>>> though. I've checked in a second try at dealing with things, can
>>>>>>> you try it? --[[Joey]]
>>>>>>>> Do you mean that [diff](http://git.ikiwiki.info/?p=ikiwiki;a=commitdiff;h=66f35e30dcea03c631a293e2341771277543b4ae)?
>>>>>>>> If so, then it causes "Internal Server Error" for me:
>>>>>>>> Can't use string ("test.txt") as a symbol ref while "strict refs" in use at /usr/share/perl5/IkiWiki/Plugin/attachment.pm line 144.
>>>>>>>> I can rebuild Debian stable source package with CGI for Perl. Maybe it will help me? What do you think? --[[Paweł|ptecza]]
2008-07-08 18:16:36 +02:00
>>>>>>>>> Silly thinko on my part, fixed that in git.. --[[Joey]]
>>>>>>>>>> Thanks for the fix, Joey! Now CGI doesn't fails, but still no success with attaching file:
>>>>>>>>>> failed to open : No such file or directory
>>>>>>>>>> Do you have any another idea how to resolve that problem? I can try with rebuilding
>>>>>>>>>> package `perl-modules` if it's necessary in that situation. --[[Paweł|ptecza]]
2008-07-08 22:21:17 +02:00
>>>>>>>>>>> If CGI.pm is not creating a temp file, not providing a
>>>>>>>>>>> filehandle by either of its documented methods, then it's just
>>>>>>>>>>> broken; ikiwiki can't deal with that level of brokennecess.
>>>>>>>>>>> I need to find out if this affects stable in general, or just
>>>>>>>>>>> you/ubuntu. --[[Joey]]
>>>>>>>>>>>> Same thing on FreeBSD using CGI.pm 3.15. Looks like $self->{'.tmpfiles'} in CGI.pm
>>>>>>>>>>>> is not populated with the information about the uploaded file, causing tmpFileName()
>>>>>>>>>>>> to return '' (unloadInfo(), which uses the same lookup method fails in the same manner),
>>>>>>>>>>>> but I have yet to find out why this happens. --[[HenrikBrixAndersen]]
The same message I can see in the Apache log file. There is also
following warning:
Use of uninitialized value in length at /usr/share/perl5/IkiWiki/Plugin/attachment.pm line 36.
> This is unrelated, I've fixed the warning message. --[[Joey]]
Is it Ikiwiki bug or my attachment plugin is misconfigured? --[[Paweł|ptecza]]
2008-07-08 22:59:21 +02:00
> I've reproduced the bug, and it does seem to be a bug with the perl in
> debian stable/ubuntu hardy. Trying to figure it out --[[Joey]]
attachment: Support perl 5.8's buggy version of CGI.pm. This is truely horribly disgusting. CGI::tmpFileName, in current perls, is an undocumented function (which should be a clue..) that takes the original filename of an uploaded attachment, and returns the name of the tempfile that CGI has stored it in. In old perls, though, CGI::tmpFileName does not take a filename. It takes a key from the object's {'.tmpfiles'} hash. This key is something crazy like '*Fh::fh00001group' -- apparently the stringification of a filehandle object. Just to add to the fun, tmpFileName doesn't take the key, it expects a refernce to the key. Argh?! But the fun doesn't stop there, because in perl 5.8, CGI.pm is also broken in two other ways. The upload() method is supposed to return a filehandle to the temp file. It doesn't. The param() method is supposed to return a filehandle to the temp file, that stringifies to the original filename. It returns just the original filename, no filehandle. Combine all these bugs, and you end up with this disgusting commit. Since I have no way to get the filehandle, I *need* to get the tempfile name. If I had the filehandle, I could probably pass it into tmpFileName, and it might strigify to the right key name. But I don't, so the only way to determine the key is to grub through the .tmpfiles hash ourselves. And finally, one the temp file name is discovered, a filehandle can finally be obtained by (re)opening it. I recommend that this commit be reverted when perl 5.8 is a mercifully faded memory. I'm really, really, really glad I'm actually being paid for working on this right now!
2008-07-09 00:10:05 +02:00
> This was amazingly disgusting, see commit message for the full horror of
> the details. I think it's [[done]] -- at least it works on debian stable
> now. --[[Joey]]
>> Wow! It's probably the biggest Ikiwiki commit message I've ever seen :)
>> Yes, I can confirm that now the plugin works for me and I'm able to add
>> attachments to my wiki. Yupiii! :D
>> Thanks a lot, Joey! You're really great! :) --[[Paweł|ptecza]]
>> Thank you very much for your effort, Joey! :) --[[Paweł|ptecza]]