summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Dibb <beandog@gentoo.org>2010-01-01 16:13:38 +0000
committerSteve Dibb <beandog@gentoo.org>2010-01-01 16:13:38 +0000
commit73f8e93a91436f3ec258991cccffae1bea4ab3cd (patch)
tree4b4e5d27685c23bf1406dcf33737738e3c47f237 /import.ebuilds.php
parentnew mtimes (diff)
downloadznurt-org-backend-73f8e93a91436f3ec258991cccffae1bea4ab3cd.tar.gz
znurt-org-backend-73f8e93a91436f3ec258991cccffae1bea4ab3cd.tar.bz2
znurt-org-backend-73f8e93a91436f3ec258991cccffae1bea4ab3cd.zip
More precision on mtimes
git-svn-id: file:///var/svn/portage@32 3218660a-b0cf-4799-a991-8ddcc5b9e0f3
Diffstat (limited to 'import.ebuilds.php')
-rw-r--r--import.ebuilds.php88
1 files changed, 59 insertions, 29 deletions
diff --git a/import.ebuilds.php b/import.ebuilds.php
index 83f389e..67ef80e 100644
--- a/import.ebuilds.php
+++ b/import.ebuilds.php
@@ -1,6 +1,17 @@
<?
/**
+ * The procedure to update an ebuild is this -- remove the old one, and insert the new one.
+ * This is actually much simpler than trying to update everything *and* it allows the
+ * website to constantly keep a snapshot of it's current status regardless of backend
+ * activity.
+ *
+ * To distinguish between new and updated ebuilds in the database, post-run, the updated
+ * ebuilds will have a non-null value for the "udate" (update date) column. New
+ * ebuilds will have a null value.
+ */
+
+ /**
* Right now this will run fine is run as a cron job. It will clean up after itself
* if there are NO ebuilds in the tree, but if you accidentally remove an entire package
* or something, it will still only insert what's new (recently modified since last mtime).
@@ -13,7 +24,7 @@
$all = false;
if($debug) {
- $all = $verbose = true;
+ $verbose = true;
}
require_once 'header.php';
@@ -21,13 +32,12 @@
require_once 'class.portage.category.php';
require_once 'class.portage.package.php';
require_once 'class.portage.ebuild.php';
- require_once '/home/steve/svn/znurt/class.db.ebuild.php';
+ require_once 'class.db.ebuild.php';
- // Reset the status on ones that were going to be removed or updated
- $sql = "UPDATE ebuild SET status = 0 WHERE status IN (1,3);";
+ // Reset the status on ones that were going to be removed
+// $sql = "UPDATE ebuild SET status = 0 WHERE status = 3;";
- // Delete any ebuilds that were new ones
- $sql = "DELETE FROM ebuild WHERE status = 1;";
+ $sql = "DELETE FROM ebuild WHERE status > 0;";
$db->query($sql);
// Check to see if there are any ebuilds
@@ -35,22 +45,22 @@
$count = $db->getOne($sql);
// If there aren't any, then import *all* packages
- if(!$count)
+ if(!$count || $debug)
$all = true;
else {
// If there are, get the last modified time
- $sql = "SELECT MAX(mtime) FROM ebuild WHERE status = 0;";
- $mtime = $db->getOne($sql);
+ $sql = "SELECT MAX(portage_mtime) AS max_portage_mtime, MAX(cache_mtime) AS max_cache_mtime FROM ebuild WHERE status = 0;";
+ $row = $db->getRow($sql);
- if(is_null($mtime))
- $all = true;
- else {
- $x = time() - $mtime;
- $x = $x / 60;
- $mmin = intval($x) + 1;
+ if(is_array($row)) {
+ extract($row);
+
+ if(is_null($max_portage_mtime) || is_null($max_cache_mtime))
+ $all = true;
+ else
+ $min = min($max_portage_mtime, $max_cache_mtime);
}
-
}
$tree = new PortageTree();
@@ -64,10 +74,15 @@
// Find all the packages that have been updated in the last 24 hours
// Need to check the packages themselves, because something may have
// been deleted.
+ $portage = $tree->getTree();
$cache = $tree->getTree()."/metadata/cache/";
- $exec = "find $cache -type f -mmin -$mmin";
+ $tmp = tempnam('/tmp', 'znurt');
+ touch($tmp, $min);
+
+ $exec = "find $cache -type f -newer $tmp";
$arr = shell::cmd($exec);
+ unlink($tmp);
if($verbose) {
shell::msg($exec);
@@ -82,6 +97,17 @@
$arr_import[$e->category] = array_unique($arr_import[$e->category]);
}
+ // Also add any packages that were flagged when importing those
+ $sql = "SELECT c.name AS category_name, p.name AS package_name FROM package p INNER JOIN category c ON c.id = p.category WHERE p.status = 1;";
+ $arr = $db->getAll($sql);
+
+ if(count($arr)) {
+ foreach($arr as $row) {
+ $arr_import[$row['category_name']][] = $row['package_name'];
+ $arr_import[$row['category_name']] = array_unique($arr_import[$row['category_name']]);
+ }
+ }
+
ksort($arr_import);
} elseif($all) {
@@ -101,7 +127,7 @@
// Get the package IDs for reference
// and the mtimes of the ebuilds for verification
- $sql = "SELECT p.id AS package_id, c.name AS category_name, p.name AS package_name, e.pf AS ebuild_name, e.mtime, e.id AS ebuild FROM ebuild e RIGHT OUTER JOIN package p ON e.package = p.id INNER JOIN category c ON p.category = c.id ORDER BY c.name, p.name;";
+ $sql = "SELECT p.id AS package_id, c.name AS category_name, p.name AS package_name, e.pf AS ebuild_name, e.id AS ebuild FROM ebuild e RIGHT OUTER JOIN package p ON e.package = p.id INNER JOIN category c ON p.category = c.id ORDER BY c.name, p.name;";
$arr = $db->getAll($sql);
if(count($arr)) {
foreach($arr as $row) {
@@ -120,14 +146,12 @@
foreach($arr_category as $package_name) {
- // FIXME always snags the last few, so says they are
- // being updated even if they're not (to duplicate, delete
- // all ebuilds, and run this twice in a row).
if($verbose)
shell::msg("[$category_name/$package_name]");
$arr_insert = array();
$arr_delete = array();
+ $arr_update = array();
if(count($arr_ebuild_ids[$category_name][$package_name]))
$arr_db_ebuilds = array_keys($arr_ebuild_ids[$category_name][$package_name]);
@@ -159,18 +183,18 @@
if($ebuild) {
$db_ebuild = new DBEbuild($ebuild);
- if($obj_ebuild->mtime != $db_ebuild->mtime || $obj_ebuild->ctime != $db_ebuild->ctime) {
+ if(($obj_ebuild->portage_mtime != $db_ebuild->portage_mtime) || ($obj_ebuild->cache_mtime != $db_ebuild->cache_mtime)) {
+
+ $arr_update[] = $ebuild_name;
+ $arr_insert[] = $ebuild_name;
+ $arr_delete[] = $ebuild_name;
if($verbose) {
shell::msg("[update] $category_name/$ebuild_name");
}
- // Flag as being updated
+ // Flag as being updated (will be removed from end of import run)
$db_ebuild->status = 2;
- if($obj_ebuild->mtime != $db_ebuild->mtime)
- $db_ebuild->mtime = $obj_ebuild->mtime;
- if($obj_ebuild->ctime != $db_ebuild->ctime)
- $db_ebuild->ctime = $obj_ebuild->ctime;
}
}
@@ -212,6 +236,11 @@
$obj_ebuild = new PortageEbuild("$category_name/$ebuild_name");
+ if(in_array($ebuild_name, $arr_update)) {
+ $udate = $now;
+ } else
+ $udate = null;
+
$arr = array(
'package' => $package_id,
'pf' => $obj_ebuild->pf,
@@ -225,9 +254,10 @@
'p' => $obj_ebuild->_p,
'version' => $obj_ebuild->version,
'slot' => $obj_ebuild->slot,
- 'mtime' => $obj_ebuild->mtime,
- 'ctime' => $obj_ebuild->ctime,
+ 'portage_mtime' => $obj_ebuild->portage_mtime,
+ 'cache_mtime' => $obj_ebuild->cache_mtime,
'status' => 1,
+ 'udate' => $udate,
);
$db->autoExecute('ebuild', $arr, MDB2_AUTOQUERY_INSERT);