Implement restart of main application once the update is installed.

* Add support for entries in the update script being marked with
   a boolean <is-main-binary> attribute which is set to true for the main binary.
 * In UpdateInstaller::restartMainApp(), look for the file marked with <is-main-binary>
   and restart it after installation.  With the current structure, this requires that
   the main binary is included in the update, which has always been the case up till now.

   If we find that we want to do updates that do not affect the main binary, the
   <is-main-binary> attribute could be replaced with a <main-binary> string value
   at the top of the XML file.
This commit is contained in:
Robert Knight 2011-08-23 12:59:04 +01:00
parent 96b76b0443
commit eeeafb2c1a
7 changed files with 35 additions and 4 deletions

View file

@ -2,6 +2,7 @@
#include <string>
#include <sstream>
#include <stdlib.h>
inline std::string intToStr(int i)
{
@ -10,4 +11,7 @@ inline std::string intToStr(int i)
return stream.str();
}
inline bool strToBool(const std::string& str)
{
return str == "true" || atoi(str.c_str()) != 0;
}

View file

@ -309,6 +309,28 @@ void UpdateInstaller::setObserver(UpdateObserver* observer)
void UpdateInstaller::restartMainApp()
{
LOG(Warn,"Restarting main app not implemented");
LOG(Info,"restarting main app");
std::string command;
std::list<std::string> args;
for (std::vector<UpdateScriptFile>::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);
ProcessUtils::runAsync(command,args);
}
else
{
LOG(Error,"No main binary specified in update script");
}
}

View file

@ -102,6 +102,7 @@ UpdateScriptFile UpdateScript::parseFile(const TiXmlElement* element)
file.package = elementText(element->FirstChildElement("package"));
file.permissions = atoi(elementText(element->FirstChildElement("permissions")).c_str());
file.linkTarget = elementText(element->FirstChildElement("target"));
file.isMainBinary = strToBool(elementText(element->FirstChildElement("is-main-binary")));
return file;
}

View file

@ -31,19 +31,22 @@ class UpdateScriptFile
public:
UpdateScriptFile()
: permissions(0)
, isMainBinary(false)
{}
std::string path;
std::string package;
int permissions;
std::string linkTarget;
bool isMainBinary;
bool operator==(const UpdateScriptFile& other) const
{
return path == other.path &&
package == other.package &&
permissions == other.permissions &&
linkTarget == other.linkTarget;
linkTarget == other.linkTarget &&
isMainBinary == other.isMainBinary;
}
};

View file

@ -78,7 +78,6 @@ void runWithUi(int argc, char** argv, UpdateInstaller* installer)
if (dialog.restartApp())
{
LOG(Info,"Restarting app after install");
installer->restartMainApp();
}
#else

View file

@ -22,6 +22,7 @@
<size>$UPDATED_APP_SIZE</size>
<permissions>30549</permissions>
<package>app-pkg</package>
<is-main-binary>true</is-main-binary>
</file>
<!-- Test symlink !-->
<file>

View file

@ -30,6 +30,7 @@
<size>$UPDATED_APP_SIZE</size>
<permissions>30549</permissions>
<package>app-pkg</package>
<is-main-binary>true</is-main-binary>
</file>
<!-- Test symlink !-->
<file>