summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2017-05-02 12:27:09 +0545
committerPhil Davis <phil.davis@inf.org>2017-05-02 12:27:09 +0545
commitdd6ecfa27246935ca03747162b802fcd4ba36100 (patch)
tree4678e7aa71a1b1370ca48f5a0ce7a2e3cdd591d1 /src
parent74ddcdb2be383425c745c2ed9cea1649ad73d25a (diff)
downloadpfsense-dd6ecfa27246935ca03747162b802fcd4ba36100.zip
pfsense-dd6ecfa27246935ca03747162b802fcd4ba36100.tar.gz
get_pkg_info improve installed_pkgs_only case
Diffstat (limited to 'src')
-rw-r--r--src/etc/inc/pkg-utils.inc29
-rw-r--r--src/usr/local/www/pkg_mgr_installed.php15
2 files changed, 27 insertions, 17 deletions
diff --git a/src/etc/inc/pkg-utils.inc b/src/etc/inc/pkg-utils.inc
index df4ac49..0842ab9 100644
--- a/src/etc/inc/pkg-utils.inc
+++ b/src/etc/inc/pkg-utils.inc
@@ -354,6 +354,12 @@ function get_pkg_info($pkgs = 'all', $remote_repo_usage_disabled = false,
}
+ if ($installed_pkgs_only && !is_pkg_installed($pkgs)) {
+ // Return early if the caller wants just installed packages and there are none.
+ // Saves doing any calls that might access a remote package repo.
+ return array();
+ }
+
if (!function_exists('is_subsystem_dirty')) {
require_once("util.inc");
}
@@ -374,13 +380,18 @@ function get_pkg_info($pkgs = 'all', $remote_repo_usage_disabled = false,
$extra_param = "-U ";
}
- if (!$installed_pkgs_only) {
+ // If we want more than just the currently installed packages or
+ // we want up-to-date remote repo info
+ // then do a full pkg search
+ if (!$installed_pkgs_only || !$remote_repo_usage_disabled) {
$rc = pkg_exec(
"search {$extra_param}-R --raw-format json-compact " .
$pkgs, $out, $err);
}
- if (($installed_pkgs_only || ($rc != 0 && $remote_repo_usage_disabled))
- && is_pkg_installed($pkgs)) {
+
+ if (($installed_pkgs_only || $rc != 0) &&
+ $remote_repo_usage_disabled &&
+ is_pkg_installed($pkgs)) {
/*
* Fall back on pkg info to return locally installed matching
* pkgs instead, if:
@@ -391,7 +402,9 @@ function get_pkg_info($pkgs = 'all', $remote_repo_usage_disabled = false,
* but it didn't have any contents, or for other reasons
* returned an error.
* AND
- * (2) at least some pkgs matching <pattern> are installed
+ * (2) remote repo data is not required
+ * AND
+ * (3) at least some pkgs matching <pattern> are installed
*
* Following an unsuccessful attempt to access a remote repo
* catalog, the local copy is wiped clear. Thereafter any
@@ -455,8 +468,11 @@ function get_pkg_info($pkgs = 'all', $remote_repo_usage_disabled = false,
"https://github.com/pfsense/FreeBSD-ports/commits/devel/" .
$pkg_info['categories'][0] . '/' . $pkg_info['name'];
+ $pkg_is_installed = false;
+
if (is_pkg_installed($pkg_info['name'])) {
$pkg_info['installed'] = true;
+ $pkg_is_installed = true;
$rc = pkg_exec("query %v {$pkg_info['name']}", $out,
$err);
@@ -477,12 +493,15 @@ function get_pkg_info($pkgs = 'all', $remote_repo_usage_disabled = false,
$out);
} else if (is_package_installed($pkg_info['shortname'])) {
$pkg_info['broken'] = true;
+ $pkg_is_installed = true;
}
$pkg_info['desc'] = preg_replace('/\n+WWW:.*$/', '',
$pkg_info['desc']);
- $result[] = $pkg_info;
+ if (!$installed_pkgs_only || $pkg_is_installed) {
+ $result[] = $pkg_info;
+ }
unset($pkg_info);
}
diff --git a/src/usr/local/www/pkg_mgr_installed.php b/src/usr/local/www/pkg_mgr_installed.php
index c9f47d9..bf4092f 100644
--- a/src/usr/local/www/pkg_mgr_installed.php
+++ b/src/usr/local/www/pkg_mgr_installed.php
@@ -46,28 +46,19 @@ if (($_REQUEST) && ($_REQUEST['ajax'])) {
}
function get_pkg_table() {
- $installed_packages = array();
- $package_list = get_pkg_info();
+ $installed_packages = get_pkg_info('all', false, true);
- if (!$package_list) {
+ if (is_array($input_errors)) {
print("error");
exit;
}
- foreach ($package_list as $pkg) {
- if (!isset($pkg['installed']) && !isset($pkg['broken'])) {
- continue;
- }
- $installed_packages[] = $pkg;
- }
-
- $pkgtbl = "";
-
if (empty($installed_packages)) {
print ("nopkg");
exit;
}
+ $pkgtbl = "";
$pkgtbl .=' <div class="table-responsive">';
$pkgtbl .=' <table class="table table-striped table-hover table-condensed">';
$pkgtbl .=' <thead>';
OpenPOWER on IntegriCloud