diff options
Diffstat (limited to 'import.packages.php')
-rw-r--r-- | import.packages.php | 122 |
1 files changed, 88 insertions, 34 deletions
diff --git a/import.packages.php b/import.packages.php index c5ee191..5c140b6 100644 --- a/import.packages.php +++ b/import.packages.php @@ -1,12 +1,61 @@ <? -// $verbose = true; +// $verbose = true; +// $debug = false; require_once 'header.php'; require_once 'class.portage.tree.php'; require_once 'class.portage.category.php'; require_once 'class.portage.package.php'; - require_once '/home/steve/svn/znurt/class.db.package.php'; + require_once 'class.db.package.php'; + + $arr_update = array(); + + // Find the packages updated since last time + $sql = "SELECT COUNT(1) FROM package;"; + $count = $db->getOne($sql); + if(!$count || $debug) + $all = true; + else { + + $sql = "SELECT MAX(portage_mtime) FROM package;"; + $max_portage_mtime = $db->getOne($sql); + + if(is_null($max_portage_mtime)) + $all = true; + + } + + if(!$all) { + + $tree = new PortageTree(); + $categories = $tree->getCategories(); + + $tmp = tempnam('/tmp', 'znurt'); + touch($tmp, $max_portage_mtime); + + $arr = array(); + + $dir = $tree->getTree(); + + foreach($categories as $category_name) { + + $category_dir = $dir."/".$category_name; + + $exec = "find $category_dir -mindepth 1 -maxdepth 1 -type d -newer $tmp"; + $arr = array_merge($arr, shell::cmd($exec)); + } + unlink($tmp); + + foreach($arr as $name) { + + $name = str_replace($dir."/", "", $name); + $tmp = explode("/", $name); + $arr_update[$tmp[0]][] = $tmp[1]; + + } + + } $sql = "SELECT id, name FROM category ORDER BY name;"; $arr_categories = $db->getAssoc($sql); @@ -17,11 +66,6 @@ $arr_package_ids[$row['category_name']][$row['package_name']] = $row['package']; } - $sql = "SELECT MAX(ctime) max_ctime, MAX(mtime) max_mtime FROM package;"; - $arr = $db->getRow($sql); - if(is_array($arr)) - extract($arr); - $table = 'package'; foreach($arr_categories as $category_id => $category_name) { @@ -45,46 +89,56 @@ $obj_package = new PortagePackage($obj_category->name, $package_name); - $arr_insert = array('category' => $category_id, 'name' => $package_name, 'changelog' => $obj_package->changelog); + $arr_insert = array( + 'category' => $category_id, + 'name' => $package_name, + 'changelog' => $obj_package->changelog, + 'portage_mtime' => $obj_package->portage_mtime, + 'changelog_mtime' => $obj_package->changelog_mtime, + 'metadata_mtime' => $obj_package->metadata_mtime, + ); $db->autoExecute($table, $arr_insert, MDB2_AUTOQUERY_INSERT); } } - + } + + foreach($arr_update as $category_name => $arr_packages) { + foreach($arr_packages as $package_name) { - if($verbose) { - shell::msg("$category_name/$package_name"); - } - - if(!in_array($package_name, $arr_diff['insert'])) { - $package_id = $arr_package_ids[$category_name][$package_name]; + $package_id = $arr_package_ids[$category_name][$package_name]; + + if($package_id) { + + $p = new PortagePackage($category_name, $package_name); - if($package_id) { + if($p->portage_mtime > $max_portage_mtime || $debug) { - $p = new PortagePackage($obj_category->name, $package_name); - - if(($p->mtime > $max_mtime) || ($p->ctime > $max_ctime)) { - - if($verbose) { - shell::msg("Updating $category_name/$package_name id: $package_id"); - } + if($verbose) { + shell::msg("Updating $category_name/$package_name id: $package_id"); + } + + $db_package = new DBPackage($package_id); - $db_package = new DBPackage($package_id); - - if($p->mtime != $db_package->mtime) - $db_package->mtime = $p->mtime; - if($p->ctime != $db_package->ctime) - $db_package->ctime = $p->ctime; - if($p->changelog != $db_package->changelog) - $db_package->changelog = $p->changelog; - + // If the mtime of this directory changed, then a file + // somewhere has been added or deleted. Flag the status + // to make sure we examine that directory later. + if($p->portage_mtime != $db_package->portage_mtime) { + $db_package->portage_mtime = $p->portage_mtime; + $db_package->status = 1; + } + if($p->changelog_mtime != $db_package->changelog_mtime) { + $db_package->changelog_mtime = $p->changelog_mtime; + $db_package->changelog = $p->changelog; } - + + if($p->metadata_mtime != $db_package->metadata_mtime) + $db_package->metadata_mtime = $p->metadata_mtime; + } } } - } ?>
\ No newline at end of file |