From e90f1a27569ac6b9e9782646c9de92fc9534b1d2 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 5 Dec 2013 20:32:12 -0600 Subject: Implement update installer --- mmc_updater/src/UpdateInstaller.cpp | 43 +++++++++++++------------------------ 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'mmc_updater/src/UpdateInstaller.cpp') diff --git a/mmc_updater/src/UpdateInstaller.cpp b/mmc_updater/src/UpdateInstaller.cpp index 23e1a4ca..3ddc1ec0 100644 --- a/mmc_updater/src/UpdateInstaller.cpp +++ b/mmc_updater/src/UpdateInstaller.cpp @@ -51,6 +51,11 @@ void UpdateInstaller::setForceElevated(bool elevated) m_forceElevated = elevated; } +void UpdateInstaller::setFinishCmd(const std::string& cmd) +{ + m_finishCmd = cmd; +} + std::list UpdateInstaller::updaterArgs() const { std::list args; @@ -266,7 +271,7 @@ void UpdateInstaller::revert() void UpdateInstaller::installFile(const UpdateScriptFile& file) { - std::string destPath = m_installDir + '/' + file.path; + std::string destPath = file.dest; std::string target = file.linkTarget; // backup the existing file if any @@ -279,23 +284,15 @@ void UpdateInstaller::installFile(const UpdateScriptFile& file) FileUtils::mkpath(destDir.c_str()); } - if (target.empty()) - { - std::string sourceFile = m_packageDir + '/' + FileUtils::fileName(file.path.c_str()); - if (!FileUtils::fileExists(sourceFile.c_str())) - { - throw "Source file does not exist: " + sourceFile; - } - FileUtils::copyFile(sourceFile.c_str(),destPath.c_str()); - - // set the permissions on the newly extracted file - FileUtils::chmod(destPath.c_str(),file.permissions); - } - else + std::string sourceFile = file.source; + if (!FileUtils::fileExists(sourceFile.c_str())) { - // create the symlink - FileUtils::createSymLink(destPath.c_str(),target.c_str()); + throw "Source file does not exist: " + sourceFile; } + FileUtils::copyFile(sourceFile.c_str(),destPath.c_str()); + + // set the permissions on the newly extracted file + FileUtils::chmod(destPath.c_str(),file.permissions); } void UpdateInstaller::installFiles() @@ -391,19 +388,9 @@ void UpdateInstaller::restartMainApp() { try { - std::string command; + std::string command = m_installDir + '/' + m_finishCmd; std::list args; - for (std::vector::const_iterator iter = m_script->filesToInstall().begin(); - iter != m_script->filesToInstall().end(); - iter++) - { - if (iter->isMainBinary) - { - command = m_installDir + '/' + iter->path; - } - } - if (!command.empty()) { LOG(Info,"Starting main application " + command); @@ -411,7 +398,7 @@ void UpdateInstaller::restartMainApp() } else { - LOG(Error,"No main binary specified in update script"); + LOG(Error,"No main binary specified"); } } catch (const std::exception& ex) -- cgit v1.2.3