diff options
author | Renato Botelho <renato@netgate.com> | 2015-10-14 11:57:28 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2015-10-14 11:57:28 -0300 |
commit | d3ff1e596e522514af7b962bfc18af700e1449f7 (patch) | |
tree | c4f0bb44fcb1510147bc812b8eea9004f93b93ca /src/etc | |
parent | 578ae21f6b412a74a00757992cc19cb4316fe842 (diff) | |
download | pfsense-d3ff1e596e522514af7b962bfc18af700e1449f7.zip pfsense-d3ff1e596e522514af7b962bfc18af700e1449f7.tar.gz |
Run pkg update once one time every hour, like upgrade script does
Diffstat (limited to 'src/etc')
-rw-r--r-- | src/etc/inc/pkg-utils.inc | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/etc/inc/pkg-utils.inc b/src/etc/inc/pkg-utils.inc index be7a533..5d6dc81 100644 --- a/src/etc/inc/pkg-utils.inc +++ b/src/etc/inc/pkg-utils.inc @@ -108,6 +108,37 @@ function pkg_remove_prefix(&$pkg_name) { } } +/* Execute pkg update when it's necessary */ +function pkg_update($force = false) { + global $g; + + $now = strftime('%s'); + if (!$force) { + $last_update_file="{$g['varrun_path']}/{$g['product_name']}-upgrade-last-update"; + + if (file_exists($last_update_file)) { + $last_update = rtrim(file_get_contents($last_update_file), "\n"); + if (!is_numericint($last_update)) { + $last_update = 0; + } + } + + if ($last_update > 0) { + if ($now > $last_update && ($now - $last_update) <= (60 * 60)) { + return true; + } + } + } + + $rc = pkg_call("update"); + + if ($rc) { + file_put_contents($last_update_file, $now . "\n"); + } + + return $rc; +} + /* Execute a pkg call */ function pkg_call($params, $mute = false) { global $static_output, $g, $config; @@ -362,7 +393,7 @@ function get_pkg_info($pkgs = 'all', $info = 'all') { $static_output .= "\n" . gettext("Updating package repository metadada...") . "\n"; update_status($static_output); - if (!pkg_call("update")) { + if (!pkg_update()) { $input_errors[] = gettext("ERROR: An error occurred when updating packages repository. Aborting...") . "\n"; $static_output .= "\n" . gettext("ERROR: An error occurred when updating packages repository. Aborting...") . "\n"; update_status($static_output); |