From 1b808c406dc7e7e168a8170284ee701b142ca974 Mon Sep 17 00:00:00 2001 From: Steve Dibb Date: Fri, 1 Jan 2010 16:12:47 +0000 Subject: Check exact time of mtimes git-svn-id: file:///var/svn/portage@29 3218660a-b0cf-4799-a991-8ddcc5b9e0f3 --- import.packages.php | 122 +++++++++++++++++++++++++++++++++++++--------------- 1 file 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 @@ 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 -- cgit v1.2.3-65-gdbad