More updater fixage
Preserve --dir parameter after updating Allow more than one copy of a command line parameter in MultiMC Linux runner script no longer changes current directory, which allows '--dir .' Fixed unit tests, removed the obsolete one (for some legacy updater command line params that were also removed) [fixes 63127704]
This commit is contained in:
@ -46,6 +46,11 @@ void UpdateInstaller::setFinishCmd(const std::string& cmd)
|
||||
m_finishCmd = cmd;
|
||||
}
|
||||
|
||||
void UpdateInstaller::setFinishDir(const std::string &dir)
|
||||
{
|
||||
m_finishDir = dir;
|
||||
}
|
||||
|
||||
std::list<std::string> UpdateInstaller::updaterArgs() const
|
||||
{
|
||||
std::list<std::string> args;
|
||||
@ -63,6 +68,11 @@ std::list<std::string> UpdateInstaller::updaterArgs() const
|
||||
{
|
||||
args.push_back("--dry-run");
|
||||
}
|
||||
if (m_finishDir.size())
|
||||
{
|
||||
args.push_back("--dir");
|
||||
args.push_back(m_finishDir);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
@ -420,6 +430,11 @@ void UpdateInstaller::restartMainApp()
|
||||
|
||||
if (!command.empty())
|
||||
{
|
||||
if(!m_finishDir.empty())
|
||||
{
|
||||
args.push_back("--dir");
|
||||
args.push_back(m_finishDir);
|
||||
}
|
||||
LOG(Info,"Starting main application " + command);
|
||||
if(!m_dryRun)
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ class UpdateInstaller
|
||||
void setAutoClose(bool autoClose);
|
||||
void setDryRun(bool dryRun);
|
||||
void setFinishCmd(const std::string& cmd);
|
||||
void setFinishDir(const std::string& dir);
|
||||
|
||||
void setObserver(UpdateObserver* observer);
|
||||
|
||||
@ -62,6 +63,7 @@ class UpdateInstaller
|
||||
std::string m_packageDir;
|
||||
std::string m_backupDir;
|
||||
std::string m_finishCmd;
|
||||
std::string m_finishDir;
|
||||
PLATFORM_PID m_waitPid = 0;
|
||||
UpdateScript* m_script = nullptr;
|
||||
UpdateObserver* m_observer = nullptr;
|
||||
|
@ -40,6 +40,7 @@ void UpdaterOptions::parse(int argc, char** argv)
|
||||
parser.setOption("install-dir");
|
||||
parser.setOption("package-dir");
|
||||
parser.setOption("finish-cmd");
|
||||
parser.setOption("finish-dir");
|
||||
parser.setOption("script");
|
||||
parser.setOption("wait");
|
||||
parser.setOption("mode");
|
||||
@ -74,6 +75,10 @@ void UpdaterOptions::parse(int argc, char** argv)
|
||||
{
|
||||
finishCmd = parser.getValue("finish-cmd");
|
||||
}
|
||||
if (parser.getValue("finish-dir"))
|
||||
{
|
||||
finishDir = parser.getValue("finish-dir");
|
||||
}
|
||||
|
||||
showVersion = parser.getFlag("version");
|
||||
forceElevated = parser.getFlag("force-elevated");
|
||||
|
@ -15,6 +15,7 @@ class UpdaterOptions
|
||||
std::string packageDir;
|
||||
std::string scriptPath;
|
||||
std::string finishCmd;
|
||||
std::string finishDir;
|
||||
PLATFORM_PID waitPid;
|
||||
std::string logFile;
|
||||
bool showVersion;
|
||||
|
@ -138,7 +138,8 @@ int main(int argc, char** argv)
|
||||
+ ", wait-pid: " + intToStr(options.waitPid)
|
||||
+ ", script-path: " + options.scriptPath
|
||||
+ ", mode: " + intToStr(options.mode)
|
||||
+ ", finish-cmd: " + options.finishCmd);
|
||||
+ ", finish-cmd: " + options.finishCmd
|
||||
+ ", finish-dir: " + options.finishDir);
|
||||
|
||||
installer.setMode(options.mode);
|
||||
installer.setInstallDir(options.installDir);
|
||||
@ -148,6 +149,7 @@ int main(int argc, char** argv)
|
||||
installer.setForceElevated(options.forceElevated);
|
||||
installer.setAutoClose(options.autoClose);
|
||||
installer.setFinishCmd(options.finishCmd);
|
||||
installer.setFinishDir(options.finishDir);
|
||||
installer.setDryRun(options.dryRun);
|
||||
|
||||
if (options.mode == UpdateInstaller::Main)
|
||||
|
@ -44,5 +44,4 @@ macro(ADD_UPDATER_TEST CLASS)
|
||||
endmacro()
|
||||
|
||||
add_updater_test(TestParseScript)
|
||||
add_updater_test(TestUpdaterOptions)
|
||||
add_updater_test(TestFileUtils)
|
||||
|
@ -1,68 +0,0 @@
|
||||
#include "TestUpdaterOptions.h"
|
||||
|
||||
#include "FileUtils.h"
|
||||
#include "Platform.h"
|
||||
#include "TestUtils.h"
|
||||
#include "UpdaterOptions.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void TestUpdaterOptions::testOldFormatArgs()
|
||||
{
|
||||
const int argc = 6;
|
||||
char* argv[argc];
|
||||
argv[0] = strdup("updater");
|
||||
|
||||
std::string currentDir("CurrentDir=");
|
||||
const char* appDir = 0;
|
||||
|
||||
// CurrentDir is the path to the directory containing the main
|
||||
// Mendeley Desktop binary, on Linux and Mac this differs from
|
||||
// the root of the install directory
|
||||
#ifdef PLATFORM_LINUX
|
||||
appDir = "/tmp/path-to-app/lib/mendeleydesktop/libexec/";
|
||||
FileUtils::mkpath(appDir);
|
||||
#elif defined(PLATFORM_MAC)
|
||||
appDir = "/tmp/path-to-app/Contents/MacOS/";
|
||||
FileUtils::mkpath(appDir);
|
||||
#elif defined(PLATFORM_WINDOWS)
|
||||
appDir = "C:/path/to/app/";
|
||||
#endif
|
||||
currentDir += appDir;
|
||||
|
||||
argv[1] = strdup(currentDir.c_str());
|
||||
argv[2] = strdup("TempDir=/tmp/updater");
|
||||
argv[3] = strdup("UpdateScriptFileName=/tmp/updater/file_list.xml");
|
||||
argv[4] = strdup("AppFileName=/path/to/app/theapp");
|
||||
argv[5] = strdup("PID=123456");
|
||||
|
||||
UpdaterOptions options;
|
||||
options.parse(argc,argv);
|
||||
|
||||
TEST_COMPARE(options.mode,UpdateInstaller::Setup);
|
||||
#ifdef PLATFORM_LINUX
|
||||
TEST_COMPARE(options.installDir,"/tmp/path-to-app");
|
||||
#elif defined(PLATFORM_MAC)
|
||||
// /tmp is a symlink to /private/tmp on Mac
|
||||
TEST_COMPARE(options.installDir,"/private/tmp/path-to-app");
|
||||
#else
|
||||
TEST_COMPARE(options.installDir,"C:/path/to/app/");
|
||||
#endif
|
||||
TEST_COMPARE(options.packageDir,"/tmp/updater");
|
||||
TEST_COMPARE(options.scriptPath,"/tmp/updater/file_list.xml");
|
||||
TEST_COMPARE(options.waitPid,123456);
|
||||
|
||||
for (int i=0; i < argc; i++)
|
||||
{
|
||||
free(argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int,char**)
|
||||
{
|
||||
TestList<TestUpdaterOptions> tests;
|
||||
tests.addTest(&TestUpdaterOptions::testOldFormatArgs);
|
||||
return TestUtils::runTest(tests);
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class TestUpdaterOptions
|
||||
{
|
||||
public:
|
||||
void testOldFormatArgs();
|
||||
};
|
||||
|
Reference in New Issue
Block a user