From df3500b274916b28a4698e5b30599d623f2db322 Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Mon, 1 Feb 2016 12:13:59 -0500 Subject: [PATCH] Update sysadm-update with the upcoming startUpdates() internal call, will doc it later when its finished --- src/library/sysadm-update.cpp | 51 +++++++++++++++++++++++++++++++++++ src/library/sysadm-update.h | 1 + 2 files changed, 52 insertions(+) diff --git a/src/library/sysadm-update.cpp b/src/library/sysadm-update.cpp index fc345cf..b222466 100644 --- a/src/library/sysadm-update.cpp +++ b/src/library/sysadm-update.cpp @@ -4,6 +4,7 @@ // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== +#include #include "sysadm-general.h" #include "sysadm-update.h" #include "sysadm-global.h" @@ -98,3 +99,53 @@ QJsonObject Update::listBranches() { return retObject; } + +// Kickoff an update process +QJsonObject Update::startUpdate(QJsonObject jsin) { + QJsonObject retObject; + + QStringList keys = jsin.keys(); + if (! keys.contains("target") ) { + retObject.insert("error", "Missing required key 'target'"); + return retObject; + } + // Save the target + QString target; + target = jsin.value("target").toString(); + + QString flags; + if ( target == "chbranch" ) { + if (! keys.contains("branch") ) { + retObject.insert("error", "Missing required key 'branch'"); + return retObject; + } + flags = "chbranch " + jsin.value("branch").toString(); + } else if ( target == "pkgupdate" ) { + flags = "pkgupdate"; + } else if ( target == "fbsdupdate" ) { + flags = "fbsdupdate"; + } else if ( target == "fbsdupdatepkgs" ) { + flags = "fbsdupdatepkgs"; + } else if ( target == "standalone" ) { + if (! keys.contains("tag") ) { + retObject.insert("error", "Missing required key 'tag'"); + return retObject; + } + flags = "install " + jsin.value("tag").toString(); + } else { + // Ruh-roh + retObject.insert("error", "Unknown target key: " + target); + return retObject; + } + + // Create a unique ID for this queued action + QString ID = QUuid::createUuid().toString(); + + //DISPATCHER::queueProcess(ID, "pc-updatemanager " + flags).split("\n"); + + // Return some details to user that the action was queued + retObject.insert("command", "pc-updatemanger " + flags); + retObject.insert("comment", "Task Queued"); + retObject.insert("queueid", ID); + return retObject; +} diff --git a/src/library/sysadm-update.h b/src/library/sysadm-update.h index efc7e3d..1a96ded 100644 --- a/src/library/sysadm-update.h +++ b/src/library/sysadm-update.h @@ -16,6 +16,7 @@ class Update{ public: static QJsonObject checkUpdates(); static QJsonObject listBranches(); + static QJsonObject startUpdate(QJsonObject); }; } //end of pcbsd namespace