X-Git-Url: http://git.pjr.cc/?p=glcas.git;a=blobdiff_plain;f=plugins%2Frepo.php;h=54f35576f54406b614458f90b3797b60edc041c9;hp=48ffae01879f10006f8c7843279825995144d116;hb=fc40a152c4238a9208086bb1203add8322861675;hpb=136e5dafcbb81dc6e347a6936e715d8ac134c5a7 diff --git a/plugins/repo.php b/plugins/repo.php index 48ffae0..54f3557 100644 --- a/plugins/repo.php +++ b/plugins/repo.php @@ -1,6 +1,7 @@ "; + $uconf = unserialize($this->config->getConfigVar("repodata")); + $repostore = $this->config->getConfigVar("storagelocation"); + //print_r($uconf); + //echo ""; + + foreach($uconf as $rkey => $repo) { + echo "Repo $rkey: ".$repo["desc"]."
"; + if(!isset($repo["expiretime"])) { + echo " - Expire time not set, setting to 2 days by default
"; + $uconf[$rkey]["expiretime"] = 2; + $repo["expiretime"] = 2; + $this->config->setConfigVar("repodata", serialize($uconf)); + $this->config->saveConfig(); + } + + if(file_exists("$repostore/$rkey/repodata/repoupdate.lock")) { + echo " - Repo locked for update
"; + + } + + // we still do this next bit, even if its locked because it may be a stray file + echo " - Expire time is ".$repo["expiretime"]." days, checking repo
"; + error_log("checking $repostore/$rkey/repodata/repomd.xml"); + $tdiff = time() - filemtime("$repostore/$rkey/repodata/repomd.xml"); + $maxtdiff = $repo["expiretime"] * 24 * 3600; + if($tdiff > $maxtdiff) { + echo " - updating repo
"; + $this->updateRepo($rkey); + } else { + echo " - not updating repo
"; + } + } + } function go($url) { @@ -278,8 +316,34 @@ class GLCASRepo { // or a range (watching and sending) // TODO: it may be advicable to start the download as a seperate cli process rather then something goin on here // so it definitely cant be interrupted. - - + + // check for a 404 file and wait 2 if it exists - i should really check the timestamp for an updated + // file, but thats too much effort for now: TODO: check timestamp on 404 file + $slept = 0; + while(!file_exists("$filename")) { + clearstatcache(); + sleep(1); + $slept += 1; + error_log("Sleeping waiting for file"); + + // if 404 file exists, we wait much less time + if(file_exists("$filename.404") && $slept > 2) { + header("HTTP/1.0 404 Not Found"); + return; + } + if($slept > 10) { + header("HTTP/1.0 404 Not Found"); + return; + } + } + + clearstatcache(); + if(is_dir($filename)) { + + header("Location: ".$_SERVER["REQUEST_URI"]."/"); + return; + } + // first, getting and sending - this is easy. if (!$ranged) { @@ -463,7 +527,7 @@ class GLCASRepo { error_log("background downloader, start"); global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; if(file_exists("$WEB_ROOT_FS/../bin/downloadfile.php")) { - $scall = "/usr/bin/php $WEB_ROOT_FS/../bin/downloadfile.php '$url' '$file' > /dev/null 2>&1 &"; + $scall = "/usr/bin/php $WEB_ROOT_FS/../bin/downloadfile.php '$url' '$file' > /tmp/dllog 2>&1 &"; system($scall); } else { error_log("cant find download helper... dieing"); @@ -771,7 +835,7 @@ class GLCASRepo { } } - function addRepo($desc, $os, $version, $arch, $other, $shorturl, $prefix, $repurl, $repotype, $init) + function addRepo($desc, $os, $version, $arch, $other, $shorturl, $prefix, $repurl, $repotype, $init, $expiretime) { $uconf = $this->config->getConfigVar("repodata"); @@ -784,6 +848,7 @@ class GLCASRepo { $cs["prefix"] = $prefix; $cs["url"] = $repurl; $cs["repotype"] = $repotype; + $cs["expiretime"] = $expiretime; $ckey = 0; @@ -832,29 +897,18 @@ class GLCASRepo { if(!file_exists("$repostore/$repokey/repodata")) { mkdir("$repostore/$repokey/repodata"); } + + error_log("background yum repo update, start"); + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + if(file_exists("$WEB_ROOT_FS/../bin/downloadfile.php")) { + $scall = "/usr/bin/php $WEB_ROOT_FS/../bin/updateyumrepo.php '$repourl' '$repostore/$repokey/' > /tmp/updateyumrepo.$repokey.log 2>&1 &"; + system($scall); + } else { + error_log("cant find download yum helper... dieing"); + } + //ignore_user_abort(true); - $actionurl = "$repourl/repodata/repomd.xml"; - $repomdxml = file_get_contents($actionurl); - file_put_contents("$repostore/$repokey/repodata/repomd.xml", $repomdxml); - - $xml = simplexml_load_file("$repostore/$repokey/repodata/repomd.xml"); - - - foreach($xml as $key => $var) { - //echo "for key $key has:\n"; - //print_r($var); - if($key == "data") { - $fileloc = $var->location["href"]; - if(!file_exists("$repostore/$repokey/$fileloc")) { - error_log("getting $fileloc for $repokey on $repourl"); - $dlfile = file_get_contents("$repourl/$fileloc"); - file_put_contents("$repostore/$repokey/$fileloc", $dlfile); - } else { - error_log("Not getting $fileloc because we already have it"); - } - } - } } function getRepo($id)