another try at dealing with CGI.pm problem
authorJoey Hess <joey@kodama.kitenet.net>
Tue, 8 Jul 2008 15:25:30 +0000 (11:25 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Tue, 8 Jul 2008 15:25:30 +0000 (11:25 -0400)
open the temp file if all attempts to get a fd fail

IkiWiki/Plugin/attachment.pm
doc/bugs/attachment:_failed_to_get_filehandle.mdwn

index f4f64b46a54ec9ad574cebf3b7715080d0882343..ed1cd61fe567c3d5cf845e5c647850de8556aa26 100644 (file)
@@ -88,6 +88,10 @@ sub formbuilder (@) { #{{{
                # of the temp file that CGI writes the upload to.
                my $tempfile=$q->tmpFileName($filename);
                
+               if (! defined $tempfile) {
+                       error("failed to determine temp filename");
+               }
+
                $filename=IkiWiki::titlepage(
                        IkiWiki::possibly_foolish_untaint(
                                attachment_location($form->field('page')).
@@ -136,7 +140,9 @@ sub formbuilder (@) { #{{{
                                # needed by old CGI versions
                                $fh=$q->param('attachment');
                                if (! defined $fh || ! ref $fh) {
-                                       error("failed to get filehandle");
+                                       # even that doesn't always work,
+                                       # fall back to opening the tempfile
+                                       open($fh, "<", $tempfile) || error("failed to open $tempfile: $!");
                                }
                        }
                        binmode($fh);
index e5d4756fc8e8a8252042f433fc1db9ebf0d8bf3b..906d01e245d33290b5d207d8acc12dc4ee5a6c56 100644 (file)
@@ -54,6 +54,15 @@ the error message like below:
 
 >>>>>> --[[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]]
+
 The same message I can see in the Apache log file. There is also
 following warning: