yeah.
authorpaulr <me@pjr.cc>
Wed, 27 Jul 2011 22:57:36 +0000 (08:57 +1000)
committerpaulr <me@pjr.cc>
Wed, 27 Jul 2011 22:57:36 +0000 (08:57 +1000)
plugins/repo.php

index 31a257f..8512e12 100644 (file)
@@ -227,40 +227,45 @@ class GLCASRepo {
        // TODO: this is the function im working on
        function downloadAndServe($filename, $repoid, $remoteurl)
        {
+               // this is important so downloads dont die
+               ignore_user_abort(true);
+               
+               // get the configurations we need
                $uconf = unserialize($this->config->getConfigVar("repodata"));
                $repostore = $this->config->getConfigVar("storagelocation");
                
                // this is the tricky one for ranges.
                
                // check if a download exists
-               if(file_exists("$actualfile.tmp.data.deleteme")) {
+               if(file_exists("$filename.tmp.data.deleteme")) {
                        // a download exists, does it still work
-                       $localtmpfh = fopen("$actualfile.tmp.data.deleteme", "r");
+                       $localtmpfh = fopen("$filename.tmp.data.deleteme", "r");
                        $lockres = flock($localtmpfh, LOCK_EX|LOCK_NB);
                        if(!$lockres) {
                                error_log("flock did fail, all is right with the world a download is in progress");
                        } else {
-                               unlink("$actualfile.tmp.data.deleteme");
-                               unlink("$actualfile.tmp.data.deleteme.size");
+                               unlink("$filename.tmp.data.deleteme");
+                               unlink("$filename.tmp.data.deleteme.size");
                        }
                }
 
-               
-               $localfile = fopen($actualfile.".tmp.data.deleteme", "w");                              
-               $localsizefile = fopen($actualfile.".tmp.data.deleteme.size", "w");
+               // open the remote file
+               $rf = fopen($remoteurl, "r");
                
                
                // get the headers from the remote request and use them to hurt people
+               $contentlen = 0;
                foreach($http_response_header as $key => $val) {
                        if(preg_match("/HTTP.*30[1-9].*/", $val)) {
                                error_log("got a 30x, must be a directory");
-                               mkdir($actualfile);
+                               mkdir($filename);
                                header("Location: ".$_SERVER["REQUEST_URI"]."/");
                                return;
                        }
                        // get content length form upstream and print
                        if(preg_match("/^Content-Length:.*/", $val)) {
-                               $clen = $val;
+                               // WARNING, THIS IS NOT RIGHT
+                               $contentlen = $val;
                                header($val);
                        }
                        // get content type from upstream and print
@@ -268,6 +273,11 @@ class GLCASRepo {
                                header($val);   
                        }
                }
+               
+               // open the local files
+               $localfile = fopen($filename.".tmp.data.deleteme", "w");                                
+               $localsizefile = fopen($filename.".tmp.data.deleteme.size", "w");
+               
        }
        
        // this is a nightmare