aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/attachment.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-07-08 18:10:05 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-07-08 18:10:53 -0400
commitad02f69836d988b339c570cfc325b16c1ca88cd3 (patch)
treeea20e3e785d6925958d1449d58020d1475a963f9 /IkiWiki/Plugin/attachment.pm
parent2e5785907d6bca9119b1ac0bba31b2260e357613 (diff)
downloadikiwiki-ad02f69836d988b339c570cfc325b16c1ca88cd3.tar
ikiwiki-ad02f69836d988b339c570cfc325b16c1ca88cd3.tar.gz
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!
Diffstat (limited to 'IkiWiki/Plugin/attachment.pm')
-rw-r--r--IkiWiki/Plugin/attachment.pm14
1 files changed, 11 insertions, 3 deletions
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm
index 84bf64390..ef6d79a9c 100644
--- a/IkiWiki/Plugin/attachment.pm
+++ b/IkiWiki/Plugin/attachment.pm
@@ -89,9 +89,17 @@ sub formbuilder (@) { #{{{
# This is an (apparently undocumented) way to get the name
# of the temp file that CGI writes the upload to.
my $tempfile=$q->tmpFileName($filename);
-
if (! defined $tempfile || ! length $tempfile) {
- error("failed to determine tempfile name");
+ # perl 5.8 needs an alternative, awful method
+ if ($q =~ /HASH/ && exists $q->{'.tmpfiles'}) {
+ foreach my $key (keys(%{$q->{'.tmpfiles'}})) {
+ $tempfile=$q->tmpFileName(\$key);
+ last if defined $tempfile && length $tempfile;
+ }
+ }
+ if (! defined $tempfile || ! length $tempfile) {
+ error("CGI::tmpFileName failed to return the uploaded file name");
+ }
}
$filename=IkiWiki::titlepage(
@@ -145,7 +153,7 @@ sub formbuilder (@) { #{{{
# even that doesn't always work,
# fall back to opening the tempfile
$fh=undef;
- open($fh, "<", $tempfile) || error("failed to open $tempfile: $!");
+ open($fh, "<", $tempfile) || error("failed to open \"$tempfile\": $!");
}
}
binmode($fh);