summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2015-10-14 11:57:28 -0300
committerRenato Botelho <renato@netgate.com>2015-10-14 11:57:28 -0300
commitd3ff1e596e522514af7b962bfc18af700e1449f7 (patch)
treec4f0bb44fcb1510147bc812b8eea9004f93b93ca /src
parent578ae21f6b412a74a00757992cc19cb4316fe842 (diff)
downloadpfsense-d3ff1e596e522514af7b962bfc18af700e1449f7.zip
pfsense-d3ff1e596e522514af7b962bfc18af700e1449f7.tar.gz
Run pkg update once one time every hour, like upgrade script does
Diffstat (limited to 'src')
-rw-r--r--src/etc/inc/pkg-utils.inc33
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);
OpenPOWER on IntegriCloud