luci-app-opkg: honor installed flag to skip half-installed packages

Do not consider half-installed packages (which happens after an
installation failure) to be installed.

Ref: https://github.com/openwrt/luci/pull/2775
Signed-off-by: Dirk Brenken <dev@brenken.org>
[split into multiple commits, refactored code, use local variables]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-06-19 11:21:18 +02:00
parent cffeee49d7
commit 88282c14cf

View file

@ -134,7 +134,12 @@ function display(pattern)
var btn, ver; var btn, ver;
if (currentDisplayMode === 'updates') { if (currentDisplayMode === 'updates') {
var avail = packages.available.pkgs[name]; var avail = packages.available.pkgs[name],
inst = packages.installed.pkgs[name];
if (!inst || !inst.installed)
continue;
if (!avail || compareVersion(avail.version, pkg.version) <= 0) if (!avail || compareVersion(avail.version, pkg.version) <= 0)
continue; continue;
@ -149,6 +154,9 @@ function display(pattern)
}, _('Upgrade…')); }, _('Upgrade…'));
} }
else if (currentDisplayMode === 'installed') { else if (currentDisplayMode === 'installed') {
if (!pkg.installed)
continue;
ver = truncateVersion(pkg.version || '-'); ver = truncateVersion(pkg.version || '-');
btn = E('div', { btn = E('div', {
'class': 'btn cbi-button-negative', 'class': 'btn cbi-button-negative',
@ -157,15 +165,17 @@ function display(pattern)
}, _('Remove')); }, _('Remove'));
} }
else { else {
var inst = packages.installed.pkgs[name];
ver = truncateVersion(pkg.version || '-'); ver = truncateVersion(pkg.version || '-');
if (!packages.installed.pkgs[name]) if (!inst || !inst.installed)
btn = E('div', { btn = E('div', {
'class': 'btn cbi-button-action', 'class': 'btn cbi-button-action',
'data-package': name, 'data-package': name,
'click': handleInstall 'click': handleInstall
}, _('Install…')); }, _('Install…'));
else if (packages.installed.pkgs[name].version != pkg.version) else if (inst.installed && inst.version != pkg.version)
btn = E('div', { btn = E('div', {
'class': 'btn cbi-button-positive', 'class': 'btn cbi-button-positive',
'data-package': name, 'data-package': name,