firmware: proper kernel size, unify format with pkg

This commit is contained in:
Franco Fichtner 2018-11-29 08:04:44 +00:00
parent 92c7681c87
commit 453946df33
2 changed files with 11 additions and 7 deletions

View File

@ -46,14 +46,18 @@ class FirmwareController extends ApiControllerBase
*/
protected function formatBytes($bytes)
{
if (preg_match('/[^0-9]/', $bytes)) {
/* already processed */
return $bytes;
}
if ($bytes >= (1024 * 1024 * 1024)) {
return sprintf("%d GB", $bytes / (1024 * 1024 * 1024));
return sprintf('%.1F%s', $bytes / (1024 * 1024 * 1024), 'GiB');
} elseif ($bytes >= 1024 * 1024) {
return sprintf("%d MB", $bytes / (1024 * 1024));
return sprintf('%.1F%s', $bytes / (1024 * 1024), 'MiB');
} elseif ($bytes >= 1024) {
return sprintf("%d KB", $bytes / 1024);
return sprintf('%.1F%s', $bytes / 1024, 'KiB');
} else {
return sprintf("%d bytes", $bytes);
return sprintf('%d%s', $bytes, 'B');
}
}
@ -739,11 +743,11 @@ class FirmwareController extends ApiControllerBase
$translated[$key] = $expanded[$index++];
if (empty($translated[$key])) {
$translated[$key] = gettext('N/A');
} elseif ($key == 'flatsize') {
$translated[$key] = $this->formatBytes($translated[$key]);
}
}
/* XXX fixup kernel/base set size */
/* mark remote packages as "provided", local as "installed" */
$translated['provided'] = $type == 'remote' ? "1" : "0";
$translated['installed'] = $type == 'local' ? "1" : "0";

View File

@ -41,4 +41,4 @@ opnsense-update -Tb || BL=1
opnsense-update -Tk || KL=1
echo "base${SEP}${BV%-*}${SEP}${OS} userland set${SEP}${BS}${SEP}${BL}${SEP}${LIC}"
echo "kernel${SEP}${KV%-*}${SEP}${OS} kernel set${SEP}${BS}${SEP}${KL}${SEP}${LIC}"
echo "kernel${SEP}${KV%-*}${SEP}${OS} kernel set${SEP}${KS}${SEP}${KL}${SEP}${LIC}"