not entirely sure, think its all the messaging components
[glcas.git] / plugins / repo.php
index 9d1de84..1546e61 100644 (file)
@@ -7,63 +7,97 @@ class GLCASRepo {
        function __construct($config)
        {
                $this->config = $config;
-               if($this->config->getConfigVar("storagelocation") == false) {
+               if($this->config->getConfig("storagelocation") == false) {
                        global $WEB_ROOT_FS;
                        $storloc = "$WEB_ROOT_FS/../var/glcas/cache/";
                        if(!file_exists($storloc)) mkdir($storloc);
-                       $this->config->setConfigVar("storagelocation", realpath($storloc));
-                       $this->config->saveConfig();
+                       $this->config->setConfig("storagelocation", realpath($storloc));
                        error_log("set storage location, $storloc");
                }
        }
        
+       
+       // with the move to the sqlite db, this is going to get painful
        function cron()
        {
                //echo "<pre>";
-               $uconf = unserialize($this->config->getConfigVar("repodata"));
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = unserialize($this->config->getConfig("repodata"));
+               $repostore = $this->config->getConfig("storagelocation");
                //print_r($uconf);
                //echo "</pre>";
                
                foreach($uconf as $rkey => $repo) {
                        echo "Repo $rkey: ".$repo["desc"]."<br>";
+                       if(isset($repo["frozen"])) {
+                               error_log("repo froze set");
+                               $repofrozen = $repo["frozen"];
+                       } else {
+                               error_log("repo froze not set");
+                               $repofrozen = false;
+                       }
                        if(!isset($repo["expiretime"])) {
                                echo " - Expire time not set, setting to 2 days by default<br>";
                                $uconf[$rkey]["expiretime"] = 2;
                                $repo["expiretime"] = 2;
-                               $this->config->setConfigVar("repodata", serialize($uconf));
+                               $this->config->setConfig("repodata", serialize($uconf));
                                $this->config->saveConfig();                            
                        }
                        
                        if(!isset($repo["repotype"])) {
                                echo "<font color=\"red\">Repo type not set for repo, setting to yum</font><br>";
                                $uconf[$rkey]["repotype"] = "YUM";
-                               $this->config->setConfigVar("repodata", serialize($uconf));
+                               $this->config->setConfig("repodata", serialize($uconf));
                                $this->config->saveConfig();                            
                        } else if($repo["repotype"] == "YUM") {
-                               if(file_exists("$repostore/$rkey/repodata/repoupdate.lock")) {
-                                       echo " - <font color=\"red\">Repo locked for update</font><br>";
-                                       
-                               }
-                               
-                               // 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<br>";
-                               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 " - <font color=\"green\">updating repo</font><br>";
-                                       $this->updateRepo($rkey);
+                               if($repofrozen) {
+                                       error_log("repo frozen");
+                                       echo " - <font color=\"blue\">Repo Frozen</font><br>";
                                } else {
-                                       echo " - not updating repo<br>";
+                                       if(file_exists("$repostore/$rkey/repodata/repoupdate.lock")) {
+                                               echo " - <font color=\"red\">Repo locked for update</font><br>";
+                                               
+                                       }
+                                       
+                                       // 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<br>";
+                                       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 " - <font color=\"green\">updating repo</font><br>";
+                                               $this->updateRepo($rkey);
+                                       } else {
+                                               echo " - not updating repo<br>";
+                                       }
                                }
                        } else if($repo["repotype"] == "APT") {
-                               if(file_exists("$repostore/$rkey/update.lock")) {
-                                       echo " - <font color=\"red\">Repo locaked for update</font><br>";
+                               if($repofrozen) {
+                                       error_log("repo frozen");
+                                       echo " - <font color=\"blue\">Repo Frozen</font><br>";
+                               } else {
+                                       if(file_exists("$repostore/$rkey/update.lock")) {
+                                               echo " - <font color=\"red\">Repo locaked for update</font><br>";
+                                       }
+                                       echo " - Expire time is ".$repo["expiretime"]." days, checking repo<br>";
+                                       $maxtdiff = $repo["expiretime"] * 24 * 3600;
+                                       // now we check for outdated release files
+                                       $dh = opendir("$repostore/$rkey/dists/");
+                                       $needsupdate = false;
+                                       while(($fn = readdir($dh))!==false) {
+                                               if($fn != "." && $fn != "..") {
+                                                       if(file_exists("$repostore/$rkey/dists/$fn/Release")) {
+                                                               $tdiff = time() -  filemtime("$repostore/$rkey/dists/$fn/Release");
+                                                               if($tdiff > $maxtdiff) $needsupdate = true;
+                                                       }
+                                               }
+                                       }
+                                       if($needsupdate) {
+                                               echo " - Spawn updater<br>";
+                                               $this->updateRepo($rkey);
+                                       } else {
+                                               echo " - Up to date<br>";
+                                       }
                                }
-                               echo " - Expire time is ".$repo["expiretime"]." days, checking repo<br>";
-                               $maxtdiff = $repo["expiretime"] * 24 * 3600;
-                               $this->updateRepo($rkey);
                        }
                }
        }
@@ -120,8 +154,8 @@ class GLCASRepo {
                $xurl = split("[/,]", $url);
 
                // first get the config
-               $uconf = unserialize($this->config->getConfigVar("repodata"));
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = unserialize($this->config->getConfig("repodata"));
+               $repostore = $this->config->getConfig("storagelocation");
 
                // preset matched to -1
                $matched = -1;
@@ -223,8 +257,8 @@ class GLCASRepo {
 
        function serveUpFile($actualfile, $repoid)
        {
-               $uconf = unserialize($this->config->getConfigVar("repodata"));
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = unserialize($this->config->getConfig("repodata"));
+               $repostore = $this->config->getConfig("storagelocation");
 
                // figure out the range header garbage that centos/redhat send
                if(isset($_SERVER["HTTP_RANGE"])) {
@@ -311,8 +345,8 @@ class GLCASRepo {
                clearstatcache();
 
                // get the configurations we need
-               $uconf = unserialize($this->config->getConfigVar("repodata"));
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = unserialize($this->config->getConfig("repodata"));
+               $repostore = $this->config->getConfig("storagelocation");
 
 
 
@@ -709,10 +743,40 @@ class GLCASRepo {
                return $glt;
        }
 
+       function freezeRepo($rkey)
+       {
+               
+               $uconf = $this->config->getConfig("repodata");
+               $repostore = $this->config->getConfig("storagelocation");
+
+               if($uconf !== false) {
+                       $conf = unserialize($uconf);
+                       foreach($conf as $key => $vla) {
+                               if($key == $rkey) {
+                                       if(isset($conf["$rkey"]["frozen"])) {
+                                               if($conf["$rkey"]["frozen"]) {
+                                                       $conf["$rkey"]["frozen"] = false;
+                                                       error_log("Unfreeze repo");
+                                               } else {
+                                                       $conf["$rkey"]["frozen"] = true;
+                                                       error_log("freeze repo");
+                                               }
+                                       } else {
+                                               $conf["$rkey"]["frozen"] = true;
+                                       }
+                                       $nconf = serialize($conf);
+                                       error_log("freeze repo as $rkey");
+                                       $this->config->setConfig("repodata", $nconf);
+                                       $this->config->saveConfig();
+                               }
+                       }
+               }
+       }
+       
        function deleteRepo($rkey)
        {
-               $uconf = $this->config->getConfigVar("repodata");
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = $this->config->getConfig("repodata");
+               $repostore = $this->config->getConfig("storagelocation");
 
                if($uconf !== false) {
                        $conf = unserialize($uconf);
@@ -722,7 +786,7 @@ class GLCASRepo {
                                        $nconf = serialize($conf);
                                        system("rm -rf $repostore/$key");
                                        error_log("remove repo as $rkey");
-                                       $this->config->setConfigVar("repodata", $nconf);
+                                       $this->config->setConfig("repodata", $nconf);
                                        $this->config->saveConfig();
                                }
                        }
@@ -731,7 +795,7 @@ class GLCASRepo {
 
        function addRepo($desc, $os, $version, $arch, $other, $shorturl, $prefix, $repurl, $repotype, $init, $expiretime, $blocklist=null)
        {
-               $uconf = $this->config->getConfigVar("repodata");
+               $uconf = $this->config->getConfig("repodata");
 
                $cs["desc"] = $desc;
                $cs["os"] = $os;
@@ -762,11 +826,11 @@ class GLCASRepo {
                $nconf = serialize($conf);
 
                error_log("add repo as $ckey");
-               $this->config->setConfigVar("repodata", $nconf);
+               $this->config->setConfig("repodata", $nconf);
                $this->config->saveConfig();
 
                // now create the base structure in the repo
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $repostore = $this->config->getConfig("storagelocation");
 
 
                // now call update repo
@@ -777,6 +841,10 @@ class GLCASRepo {
        {
                // we only do yum yet
                $repod = $this->getRepo($repokey);
+               if(isset($repod["frozen"])) if($repod["frozen"]) {
+                       error_log("in update repo for frozen repo, ignore update");
+                       return;
+               }
                
                error_log("in update repo");
 
@@ -786,7 +854,7 @@ class GLCASRepo {
        
        function updateRepoApt($repokey)
        {
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $repostore = $this->config->getConfig("storagelocation");
 
                $repod = $this->getRepo($repokey);
 
@@ -795,6 +863,13 @@ class GLCASRepo {
                if(!file_exists("$repostore/$repokey")) {
                        mkdir("$repostore/$repokey");
                }
+               
+               if(!file_exists("$repostore/$repokey/dists/")) {
+                       mkdir("$repostore/$repokey/dists/");
+                       // no point trying to update if we have no dists directory
+                       return;
+               }
+               
 
                error_log("background apt repo update, start");
                global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
@@ -808,7 +883,7 @@ class GLCASRepo {
 
        function updateRepoYum($repokey)
        {
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $repostore = $this->config->getConfig("storagelocation");
 
                $repod = $this->getRepo($repokey);
 
@@ -837,7 +912,7 @@ class GLCASRepo {
 
        function getRepo($id)
        {
-               $uconf = $this->config->getConfigVar("repodata");
+               $uconf = $this->config->getConfig("repodata");
                if($uconf !== false) {
                        $lconf = unserialize($uconf);
                        return $lconf[$id];
@@ -847,7 +922,7 @@ class GLCASRepo {
 
        function getRepos()
        {
-               $uconf = $this->config->getConfigVar("repodata");
+               $uconf = $this->config->getConfig("repodata");
                if($uconf !== false) {
                        return unserialize($uconf);
                } else return false;