summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2017-05-10 15:45:46 -0300
committerRenato Botelho <renato@netgate.com>2017-05-10 15:45:46 -0300
commit3459c6ec61e40d41f14c366c08f30f981e78ba0f (patch)
tree49326721c34db2831ad40ed8536bea951eacb987
parent6e0bfeb217a5c812dfe4f0d217a318476f5815ca (diff)
parentdd6ecfa27246935ca03747162b802fcd4ba36100 (diff)
downloadpfsense-3459c6ec61e40d41f14c366c08f30f981e78ba0f.zip
pfsense-3459c6ec61e40d41f14c366c08f30f981e78ba0f.tar.gz
Merge pull request #3719 from phil-davis/no-packages
-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 7fbb37f..6e8a46e 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