Implement update installer
This commit is contained in:
@ -51,6 +51,11 @@ void UpdateInstaller::setForceElevated(bool elevated)
|
||||
m_forceElevated = elevated;
|
||||
}
|
||||
|
||||
void UpdateInstaller::setFinishCmd(const std::string& cmd)
|
||||
{
|
||||
m_finishCmd = cmd;
|
||||
}
|
||||
|
||||
std::list<std::string> UpdateInstaller::updaterArgs() const
|
||||
{
|
||||
std::list<std::string> 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 = file.source;
|
||||
if (!FileUtils::fileExists(sourceFile.c_str()))
|
||||
{
|
||||
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());
|
||||
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
|
||||
{
|
||||
// create the symlink
|
||||
FileUtils::createSymLink(destPath.c_str(),target.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<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);
|
||||
@ -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)
|
||||
|
@ -33,6 +33,7 @@ class UpdateInstaller
|
||||
void setWaitPid(PLATFORM_PID pid);
|
||||
void setForceElevated(bool elevated);
|
||||
void setAutoClose(bool autoClose);
|
||||
void setFinishCmd(const std::string& cmd);
|
||||
|
||||
void setObserver(UpdateObserver* observer);
|
||||
|
||||
@ -60,6 +61,7 @@ class UpdateInstaller
|
||||
std::string m_installDir;
|
||||
std::string m_packageDir;
|
||||
std::string m_backupDir;
|
||||
std::string m_finishCmd;
|
||||
PLATFORM_PID m_waitPid;
|
||||
UpdateScript* m_script;
|
||||
UpdateObserver* m_observer;
|
||||
|
@ -71,13 +71,14 @@ void UpdateScript::parseUpdate(const TiXmlElement* updateNode)
|
||||
UpdateScriptFile UpdateScript::parseFile(const TiXmlElement* element)
|
||||
{
|
||||
UpdateScriptFile file;
|
||||
file.path = elementText(element->FirstChildElement("name"));
|
||||
// The name within the update files folder.
|
||||
file.source = elementText(element->FirstChildElement("source"));
|
||||
// The path to install to.
|
||||
file.dest = elementText(element->FirstChildElement("dest"));
|
||||
|
||||
std::string modeString = elementText(element->FirstChildElement("permissions"));
|
||||
std::string modeString = elementText(element->FirstChildElement("mode"));
|
||||
sscanf(modeString.c_str(),"%i",&file.permissions);
|
||||
|
||||
file.linkTarget = elementText(element->FirstChildElement("target"));
|
||||
file.isMainBinary = strToBool(elementText(element->FirstChildElement("is-main-binary")));
|
||||
return file;
|
||||
}
|
||||
|
||||
|
@ -35,10 +35,12 @@ class UpdateScriptFile
|
||||
public:
|
||||
UpdateScriptFile()
|
||||
: permissions(0)
|
||||
, isMainBinary(false)
|
||||
{}
|
||||
|
||||
std::string path;
|
||||
/// Path to copy from.
|
||||
std::string source;
|
||||
/// The path to copy to.
|
||||
std::string dest;
|
||||
std::string linkTarget;
|
||||
|
||||
/** The permissions for this file, specified
|
||||
@ -46,14 +48,11 @@ class UpdateScriptFile
|
||||
*/
|
||||
int permissions;
|
||||
|
||||
bool isMainBinary;
|
||||
|
||||
bool operator==(const UpdateScriptFile& other) const
|
||||
{
|
||||
return path == other.path &&
|
||||
permissions == other.permissions &&
|
||||
linkTarget == other.linkTarget &&
|
||||
isMainBinary == other.isMainBinary;
|
||||
return source == other.source &&
|
||||
dest == other.dest &&
|
||||
permissions == other.permissions;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -111,6 +111,7 @@ void UpdaterOptions::parse(int argc, char** argv)
|
||||
AnyOption parser;
|
||||
parser.setOption("install-dir");
|
||||
parser.setOption("package-dir");
|
||||
parser.setOption("finish-cmd");
|
||||
parser.setOption("script");
|
||||
parser.setOption("wait");
|
||||
parser.setOption("mode");
|
||||
@ -140,6 +141,10 @@ void UpdaterOptions::parse(int argc, char** argv)
|
||||
{
|
||||
waitPid = static_cast<PLATFORM_PID>(atoll(parser.getValue("wait")));
|
||||
}
|
||||
if (parser.getValue("finish-cmd"))
|
||||
{
|
||||
finishCmd = parser.getValue("finish-cmd");
|
||||
}
|
||||
|
||||
showVersion = parser.getFlag("version");
|
||||
forceElevated = parser.getFlag("force-elevated");
|
||||
|
@ -14,6 +14,7 @@ class UpdaterOptions
|
||||
std::string installDir;
|
||||
std::string packageDir;
|
||||
std::string scriptPath;
|
||||
std::string finishCmd;
|
||||
PLATFORM_PID waitPid;
|
||||
std::string logFile;
|
||||
bool showVersion;
|
||||
|
@ -137,7 +137,8 @@ int main(int argc, char** argv)
|
||||
+ ", package-dir: " + options.packageDir
|
||||
+ ", wait-pid: " + intToStr(options.waitPid)
|
||||
+ ", script-path: " + options.scriptPath
|
||||
+ ", mode: " + intToStr(options.mode));
|
||||
+ ", mode: " + intToStr(options.mode)
|
||||
+ ", finish-cmd: " + options.finishCmd);
|
||||
|
||||
installer.setMode(options.mode);
|
||||
installer.setInstallDir(options.installDir);
|
||||
@ -146,6 +147,7 @@ int main(int argc, char** argv)
|
||||
installer.setWaitPid(options.waitPid);
|
||||
installer.setForceElevated(options.forceElevated);
|
||||
installer.setAutoClose(options.autoClose);
|
||||
installer.setFinishCmd(options.finishCmd);
|
||||
|
||||
if (options.mode == UpdateInstaller::Main)
|
||||
{
|
||||
|
@ -18,31 +18,10 @@ void TestUpdateScript::testV2Script()
|
||||
TEST_COMPARE(newFormat.filesToUninstall(),oldFormat.filesToUninstall());
|
||||
}
|
||||
|
||||
void TestUpdateScript::testPermissions()
|
||||
{
|
||||
UpdateScript script;
|
||||
script.parse("file_list.xml");
|
||||
|
||||
for (std::vector<UpdateScriptFile>::const_iterator iter = script.filesToInstall().begin();
|
||||
iter != script.filesToInstall().end();
|
||||
iter++)
|
||||
{
|
||||
if (iter->isMainBinary)
|
||||
{
|
||||
TEST_COMPARE(iter->permissions,0755);
|
||||
}
|
||||
if (!iter->linkTarget.empty())
|
||||
{
|
||||
TEST_COMPARE(iter->permissions,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int,char**)
|
||||
{
|
||||
TestList<TestUpdateScript> tests;
|
||||
tests.addTest(&TestUpdateScript::testV2Script);
|
||||
tests.addTest(&TestUpdateScript::testPermissions);
|
||||
return TestUtils::runTest(tests);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,5 @@ class TestUpdateScript
|
||||
{
|
||||
public:
|
||||
void testV2Script();
|
||||
void testPermissions();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user