From 733ff7f20d87e104ae0b528602c946ec63fe137b Mon Sep 17 00:00:00 2001 From: paulr Date: Thu, 28 Jul 2011 08:57:36 +1000 Subject: [PATCH] yeah. --- plugins/repo.php | 28 +++++++++++++++++++--------- 1 files changed, 19 insertions(+), 9 deletions(-) diff --git a/plugins/repo.php b/plugins/repo.php index 31a257f..8512e12 100644 --- a/plugins/repo.php +++ b/plugins/repo.php @@ -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 -- 1.7.0.4