summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-02-22 10:35:08 +0100
committerErich Eckner <git@eckner.net>2019-02-22 10:35:08 +0100
commitbc4b84d128177e7b640dfac901161e00c100e439 (patch)
tree8d0fa059770bd852f927aa7fca30af9ab2845fc0
parenta9b7ef03f1a574169f65303f37654223d980db41 (diff)
downloadarchweb32-bc4b84d128177e7b640dfac901161e00c100e439.tar.xz
lib/helper.php: available_upstream_packages() new
-rw-r--r--buildmaster/deletion-links.php14
-rw-r--r--buildmaster/to-delete.php6
-rw-r--r--lib/helper.php84
3 files changed, 88 insertions, 16 deletions
diff --git a/buildmaster/deletion-links.php b/buildmaster/deletion-links.php
index f26208a..54329bb 100644
--- a/buildmaster/deletion-links.php
+++ b/buildmaster/deletion-links.php
@@ -1,5 +1,6 @@
<?php
require_once "../init.php";
+require_once BASE . "/lib/helper.php";
require_once BASE . "/lib/mysql.php";
$edges = "";
@@ -15,18 +16,7 @@ if (array_key_exists("pkgname", $_GET))
else
$filter = "";
-$available_upstream_packages = apcu_fetch('available_upstream_packages', $apcu_success);
-if ($apcu_success == false) {
- $available_upstream_packages = explode(
- "\n",
- shell_exec(
- "find /var/lib/pacman/ -name '*.db' -exec tar -tzf {} \; " .
- "| sed -n 's,-[^-]\+-[^-]\+/$,,;T;p' " .
- "| sort -u"
- )
- );
- apcu_store('available_upstream_packages', $available_upstream_packages, 1800);
-}
+$available_upstream_packages = available_upstream_packages('pkgname');
mysql_run_query(
"CREATE TEMPORARY TABLE `available` (" .
diff --git a/buildmaster/to-delete.php b/buildmaster/to-delete.php
index df11750..579bd62 100644
--- a/buildmaster/to-delete.php
+++ b/buildmaster/to-delete.php
@@ -1,5 +1,6 @@
<?php
require_once "../init.php";
+require_once BASE . "/lib/helper.php";
require_once BASE . "/lib/mysql.php";
$result = mysql_run_query(
@@ -19,10 +20,7 @@ require_once BASE . "/lib/mysql.php";
"AND `repositories`.`is_on_master_mirror`"
);
- $available = explode(
- "\n",
- shell_exec("find /var/lib/pacman/ -name '*.db' -exec tar -tzf {} \; | sed -n 's,-[^-]\+-[^-]\+/$,,;T;p'")
- );
+ $available = available_upstream_packages('pkgname');
$available = array_combine( $available, $available);
?>
<html>
diff --git a/lib/helper.php b/lib/helper.php
index 73b97e8..59c9622 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -187,3 +187,87 @@ function add_fancy_unit($value, $unit) {
$exponent = max(0,min(count($suffixes)-1,round(log(abs($value))/log(1024)-1)));
return sprintf("%.2f %s%s", $value / pow(1024,$exponent), $suffixes[8 + $exponent], $unit);
}
+
+function parse_package_filename($filename, $repo = NULL) {
+ if (! preg_match(
+ '/^(\S+)-(([^-:]+):)?([^-:]+)-([^-]+)-([^-]+)\.pkg\.tar\.xz$/',
+ $filename,
+ $matches
+ ))
+ return;
+ $result = array(
+ 'pkgname' => $matches[1],
+ 'pkgver' => $matches[4],
+ 'pkgrel' => $matches[5],
+ 'arch' => $matches[6]
+ );
+ if (!empty($repo))
+ $result['repo'] = $repo;
+ if (empty($matches[3]))
+ $result['epoch'] = '0';
+ else
+ $result['epoch'] = $matches[3];
+
+ return $result;
+}
+
+function find_upstream_packages_in($repo) {
+ $parse_package_filename_in_repo = function($filename) use ($repo) {
+ return parse_package_filename($filename, $repo);
+ };
+ return
+ array_map(
+ $parse_package_filename_in_repo,
+ explode(
+ "\n",
+ shell_exec(
+ "tar -Oxzf /var/lib/pacman/sync/" . $repo . ".db" .
+ " | grep -xFA1 '%FILENAME%'" .
+ " | grep -vxF '%FILENAME%\n--'"
+ )
+ )
+ );
+}
+
+function available_upstream_packages($columns = NULL) {
+ $available_upstream_packages = apcu_fetch('available_upstream_packages', $apcu_success);
+ if ($apcu_success == false) {
+ $available_upstream_packages_repowise = array_map(
+ 'find_upstream_packages_in',
+ array(
+ 'core', 'extra', 'community'
+ )
+ );
+ $available_upstream_packages = array();
+ foreach ($available_upstream_packages_repowise as $sub_array)
+ $available_upstream_packages =
+ array_merge(
+ $available_upstream_packages,
+ $sub_array
+ );
+ apcu_store('available_upstream_packages', $available_upstream_packages, 1800);
+ }
+
+ if (!isset($columns))
+ return $available_upstream_packages;
+ if (!is_array($columns))
+ return array_column($available_upstream_packages, $columns);
+ $select_columns_of_interest = function($row) use ($columns) {
+ $select = function($column) use ($row) {
+ return $row[$column];
+ };
+ return
+ array_combine(
+ $columns,
+ array_map(
+ $select,
+ $columns
+ )
+ );
+ };
+ return
+ array_map(
+ $select_columns_of_interest,
+ $available_upstream_packages
+ );
+}