summaryrefslogtreecommitdiffstats
path: root/mmc_updater/src
diff options
context:
space:
mode:
Diffstat (limited to 'mmc_updater/src')
-rw-r--r--mmc_updater/src/Platform.h4
-rw-r--r--mmc_updater/src/UpdateInstaller.cpp43
-rw-r--r--mmc_updater/src/UpdateInstaller.h2
-rw-r--r--mmc_updater/src/UpdateScript.cpp9
-rw-r--r--mmc_updater/src/UpdateScript.h15
-rw-r--r--mmc_updater/src/UpdaterOptions.cpp5
-rw-r--r--mmc_updater/src/UpdaterOptions.h1
-rw-r--r--mmc_updater/src/main.cpp4
-rw-r--r--mmc_updater/src/tests/TestUpdateScript.cpp21
-rw-r--r--mmc_updater/src/tests/TestUpdateScript.h1
10 files changed, 41 insertions, 64 deletions
diff --git a/mmc_updater/src/Platform.h b/mmc_updater/src/Platform.h
index 18072b38..6d9afdfb 100644
--- a/mmc_updater/src/Platform.h
+++ b/mmc_updater/src/Platform.h
@@ -7,7 +7,9 @@
#ifdef WIN32
#define PLATFORM_WINDOWS
+ #define WIN32_LEAN_AND_MEAN
#include <windows.h>
+ #include <shellapi.h>
// disable warnings about exception specifications,
// which are not implemented in Visual C++
@@ -27,4 +29,4 @@
#define PLATFORM_PID pid_t
#else
#define PLATFORM_PID DWORD
-#endif \ No newline at end of file
+#endif
diff --git a/mmc_updater/src/UpdateInstaller.cpp b/mmc_updater/src/UpdateInstaller.cpp
index 23e1a4ca..ced6ff39 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<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 = 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_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)
diff --git a/mmc_updater/src/UpdateInstaller.h b/mmc_updater/src/UpdateInstaller.h
index 5dfa263e..1eca0bc7 100644
--- a/mmc_updater/src/UpdateInstaller.h
+++ b/mmc_updater/src/UpdateInstaller.h
@@ -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;
diff --git a/mmc_updater/src/UpdateScript.cpp b/mmc_updater/src/UpdateScript.cpp
index 606163dd..849a2217 100644
--- a/mmc_updater/src/UpdateScript.cpp
+++ b/mmc_updater/src/UpdateScript.cpp
@@ -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;
}
diff --git a/mmc_updater/src/UpdateScript.h b/mmc_updater/src/UpdateScript.h
index fec463f3..c825e35d 100644
--- a/mmc_updater/src/UpdateScript.h
+++ b/mmc_updater/src/UpdateScript.h
@@ -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;
}
};
diff --git a/mmc_updater/src/UpdaterOptions.cpp b/mmc_updater/src/UpdaterOptions.cpp
index e7809fb8..ae34562d 100644
--- a/mmc_updater/src/UpdaterOptions.cpp
+++ b/mmc_updater/src/UpdaterOptions.cpp
@@ -104,6 +104,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");
@@ -133,6 +134,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");
diff --git a/mmc_updater/src/UpdaterOptions.h b/mmc_updater/src/UpdaterOptions.h
index a8496d9f..b4473a82 100644
--- a/mmc_updater/src/UpdaterOptions.h
+++ b/mmc_updater/src/UpdaterOptions.h
@@ -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;
diff --git a/mmc_updater/src/main.cpp b/mmc_updater/src/main.cpp
index e23cf16d..fb072ab5 100644
--- a/mmc_updater/src/main.cpp
+++ b/mmc_updater/src/main.cpp
@@ -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)
{
diff --git a/mmc_updater/src/tests/TestUpdateScript.cpp b/mmc_updater/src/tests/TestUpdateScript.cpp
index 9e8c1392..30a7572a 100644
--- a/mmc_updater/src/tests/TestUpdateScript.cpp
+++ b/mmc_updater/src/tests/TestUpdateScript.cpp
@@ -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);
}
diff --git a/mmc_updater/src/tests/TestUpdateScript.h b/mmc_updater/src/tests/TestUpdateScript.h
index fd0994fe..513513d5 100644
--- a/mmc_updater/src/tests/TestUpdateScript.h
+++ b/mmc_updater/src/tests/TestUpdateScript.h
@@ -4,6 +4,5 @@ class TestUpdateScript
{
public:
void testV2Script();
- void testPermissions();
};