Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2008-04-10 15:28:39


Author: danieljames
Date: 2008-04-10 15:28:38 EDT (Thu, 10 Apr 2008)
New Revision: 44154
URL: http://svn.boost.org/trac/boost/changeset/44154

Log:
404 if there is an error extracting a file from the zip. Not always correct but
probably better than returing a blank page. A little hacky.

Text files modified:
   website/public_html/beta/common/code/boost_archive.php | 33 ++++++++++++++++++++++++++++-----
   1 files changed, 28 insertions(+), 5 deletions(-)

Modified: website/public_html/beta/common/code/boost_archive.php
==============================================================================
--- website/public_html/beta/common/code/boost_archive.php (original)
+++ website/public_html/beta/common/code/boost_archive.php 2008-04-10 15:28:38 EDT (Thu, 10 Apr 2008)
@@ -70,8 +70,8 @@
         if (! $this->extractor_)
         {
             # File doesn't exist, or we don't know how to handle it.
- header("HTTP/1.0 404 Not Found");
- $this->extractor_ = 'raw';
+ $this->extractor_ = '404';
+ $this->_init_404();
         }
         else if ($get_as_raw || $this->extractor_ == 'raw')
         {
@@ -121,8 +121,13 @@
         while ($file_handle && !feof($file_handle)) {
             $text .= fread($file_handle,8*1024);
         }
- pclose($file_handle);
- return $text;
+ if(pclose($file_handle) == 0) {
+ return $text;
+ }
+ else {
+ $this->extractor_ = '404';
+ return '';
+ }
     }
 
     function _extract_raw($unzip)
@@ -131,7 +136,11 @@
         ## header('Content-Disposition: attachment; filename="downloaded.pdf"');
         $file_handle = popen($unzip,'rb');
         fpassthru($file_handle);
- pclose($file_handle);
+ if(pclose($file_handle) != 0) {
+ // TODO: Maybe I should buffer the file so that I can return a
+ // proper 404 error.
+ echo "File not found.";
+ }
     }
     
     function content()
@@ -482,5 +491,19 @@
     {
         print $this->_content_html_pre();
     }
+
+ function _init_404()
+ {
+ header("HTTP/1.0 404 Not Found");
+ }
+
+ function _content_404()
+ {
+ # This might also be an error extracting the file, or because we don't
+ # know how to deal with the file. It would be good to give a better
+ # error in those cases.
+
+ print '<h1>404 Not Found</h1><p>File not found.</p>';
+ }
 }
 ?>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk