mirror of
https://github.com/pfsense/pfsense.git
synced 2025-10-26 11:38:35 +00:00
get_pkg_info improve installed_pkgs_only case
This commit is contained in:
parent
74ddcdb2be
commit
dd6ecfa272
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user