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:
parent
a64eebf8eb
commit
0dcf694c87
21
MultiMC.cpp
21
MultiMC.cpp
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
using namespace Util::Commandline;
|
using namespace Util::Commandline;
|
||||||
|
|
||||||
MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
|
MultiMC::MultiMC(int &argc, char **argv, bool root_override)
|
||||||
: QApplication(argc, argv), m_version{VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD,
|
: QApplication(argc, argv), m_version{VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD,
|
||||||
VERSION_CHANNEL, VERSION_BUILD_TYPE}
|
VERSION_CHANNEL, VERSION_BUILD_TYPE}
|
||||||
{
|
{
|
||||||
@ -111,14 +111,7 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
|
|||||||
QString adjustedBy;
|
QString adjustedBy;
|
||||||
// change directory
|
// change directory
|
||||||
QString dirParam = args["dir"].toString();
|
QString dirParam = args["dir"].toString();
|
||||||
if (!data_dir_override.isEmpty())
|
if (!dirParam.isEmpty())
|
||||||
{
|
|
||||||
// the override is used for tests (although dirparam would be enough...)
|
|
||||||
// TODO: remove the need for this extra logic
|
|
||||||
adjustedBy += "Test override " + data_dir_override;
|
|
||||||
dataPath = data_dir_override;
|
|
||||||
}
|
|
||||||
else if (!dirParam.isEmpty())
|
|
||||||
{
|
{
|
||||||
// the dir param. it makes multimc data path point to whatever the user specified
|
// the dir param. it makes multimc data path point to whatever the user specified
|
||||||
// on command line
|
// on command line
|
||||||
@ -130,6 +123,7 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
|
|||||||
dataPath = applicationDirPath();
|
dataPath = applicationDirPath();
|
||||||
adjustedBy += "Fallback to binary path " + dataPath;
|
adjustedBy += "Fallback to binary path " + dataPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath))
|
if(!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath))
|
||||||
{
|
{
|
||||||
// BAD STUFF. WHAT DO?
|
// BAD STUFF. WHAT DO?
|
||||||
@ -139,6 +133,11 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (root_override)
|
||||||
|
{
|
||||||
|
rootPath = binPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
QDir foo(PathCombine(binPath, ".."));
|
QDir foo(PathCombine(binPath, ".."));
|
||||||
@ -550,8 +549,10 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
|
|||||||
if(flags & DryRun)
|
if(flags & DryRun)
|
||||||
args << "--dry-run";
|
args << "--dry-run";
|
||||||
if (flags & RestartOnFinish)
|
if (flags & RestartOnFinish)
|
||||||
|
{
|
||||||
args << "--finish-cmd" << finishCmd;
|
args << "--finish-cmd" << finishCmd;
|
||||||
|
args << "--finish-dir" << data();
|
||||||
|
}
|
||||||
QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" ");
|
QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" ");
|
||||||
QFile::setPermissions(updaterBinary, (QFileDevice::Permission)0x7755);
|
QFile::setPermissions(updaterBinary, (QFileDevice::Permission)0x7755);
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MultiMC(int &argc, char **argv, const QString &root = QString());
|
MultiMC(int &argc, char **argv, bool root_override = false);
|
||||||
virtual ~MultiMC();
|
virtual ~MultiMC();
|
||||||
|
|
||||||
std::shared_ptr<SettingsObject> settings()
|
std::shared_ptr<SettingsObject> settings()
|
||||||
|
@ -286,11 +286,11 @@ QHash<QString, QVariant> Parser::parse(QStringList argv)
|
|||||||
// we were expecting an argument
|
// we were expecting an argument
|
||||||
{
|
{
|
||||||
QString name = expecting.first();
|
QString name = expecting.first();
|
||||||
|
/*
|
||||||
if (map.contains(name))
|
if (map.contains(name))
|
||||||
throw ParsingError(
|
throw ParsingError(
|
||||||
QString("Option %2%1 was given multiple times").arg(name, optionPrefix));
|
QString("Option %2%1 was given multiple times").arg(name, optionPrefix));
|
||||||
|
*/
|
||||||
map[name] = QVariant(arg);
|
map[name] = QVariant(arg);
|
||||||
|
|
||||||
expecting.removeFirst();
|
expecting.removeFirst();
|
||||||
@ -316,10 +316,11 @@ QHash<QString, QVariant> Parser::parse(QStringList argv)
|
|||||||
|
|
||||||
if (m_options.contains(name))
|
if (m_options.contains(name))
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
if (map.contains(name))
|
if (map.contains(name))
|
||||||
throw ParsingError(QString("Option %2%1 was given multiple times")
|
throw ParsingError(QString("Option %2%1 was given multiple times")
|
||||||
.arg(name, optionPrefix));
|
.arg(name, optionPrefix));
|
||||||
|
*/
|
||||||
OptionDef *option = m_options[name];
|
OptionDef *option = m_options[name];
|
||||||
if (option->type == otSwitch)
|
if (option->type == otSwitch)
|
||||||
map[name] = true;
|
map[name] = true;
|
||||||
@ -367,11 +368,11 @@ QHash<QString, QVariant> Parser::parse(QStringList argv)
|
|||||||
throw ParsingError(QString("Unknown flag %2%1").arg(flag, flagPrefix));
|
throw ParsingError(QString("Unknown flag %2%1").arg(flag, flagPrefix));
|
||||||
|
|
||||||
OptionDef *option = m_flags[flag];
|
OptionDef *option = m_flags[flag];
|
||||||
|
/*
|
||||||
if (map.contains(option->name))
|
if (map.contains(option->name))
|
||||||
throw ParsingError(QString("Option %2%1 was given multiple times")
|
throw ParsingError(QString("Option %2%1 was given multiple times")
|
||||||
.arg(option->name, optionPrefix));
|
.arg(option->name, optionPrefix));
|
||||||
|
*/
|
||||||
if (option->type == otSwitch)
|
if (option->type == otSwitch)
|
||||||
map[option->name] = true;
|
map[option->name] = true;
|
||||||
else // if (option->type == otOption)
|
else // if (option->type == otOption)
|
||||||
|
@ -46,6 +46,11 @@ void UpdateInstaller::setFinishCmd(const std::string& cmd)
|
|||||||
m_finishCmd = 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> UpdateInstaller::updaterArgs() const
|
||||||
{
|
{
|
||||||
std::list<std::string> args;
|
std::list<std::string> args;
|
||||||
@ -63,6 +68,11 @@ std::list<std::string> UpdateInstaller::updaterArgs() const
|
|||||||
{
|
{
|
||||||
args.push_back("--dry-run");
|
args.push_back("--dry-run");
|
||||||
}
|
}
|
||||||
|
if (m_finishDir.size())
|
||||||
|
{
|
||||||
|
args.push_back("--dir");
|
||||||
|
args.push_back(m_finishDir);
|
||||||
|
}
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,6 +430,11 @@ void UpdateInstaller::restartMainApp()
|
|||||||
|
|
||||||
if (!command.empty())
|
if (!command.empty())
|
||||||
{
|
{
|
||||||
|
if(!m_finishDir.empty())
|
||||||
|
{
|
||||||
|
args.push_back("--dir");
|
||||||
|
args.push_back(m_finishDir);
|
||||||
|
}
|
||||||
LOG(Info,"Starting main application " + command);
|
LOG(Info,"Starting main application " + command);
|
||||||
if(!m_dryRun)
|
if(!m_dryRun)
|
||||||
{
|
{
|
||||||
|
@ -34,6 +34,7 @@ class UpdateInstaller
|
|||||||
void setAutoClose(bool autoClose);
|
void setAutoClose(bool autoClose);
|
||||||
void setDryRun(bool dryRun);
|
void setDryRun(bool dryRun);
|
||||||
void setFinishCmd(const std::string& cmd);
|
void setFinishCmd(const std::string& cmd);
|
||||||
|
void setFinishDir(const std::string& dir);
|
||||||
|
|
||||||
void setObserver(UpdateObserver* observer);
|
void setObserver(UpdateObserver* observer);
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ class UpdateInstaller
|
|||||||
std::string m_packageDir;
|
std::string m_packageDir;
|
||||||
std::string m_backupDir;
|
std::string m_backupDir;
|
||||||
std::string m_finishCmd;
|
std::string m_finishCmd;
|
||||||
|
std::string m_finishDir;
|
||||||
PLATFORM_PID m_waitPid = 0;
|
PLATFORM_PID m_waitPid = 0;
|
||||||
UpdateScript* m_script = nullptr;
|
UpdateScript* m_script = nullptr;
|
||||||
UpdateObserver* m_observer = nullptr;
|
UpdateObserver* m_observer = nullptr;
|
||||||
|
@ -40,6 +40,7 @@ void UpdaterOptions::parse(int argc, char** argv)
|
|||||||
parser.setOption("install-dir");
|
parser.setOption("install-dir");
|
||||||
parser.setOption("package-dir");
|
parser.setOption("package-dir");
|
||||||
parser.setOption("finish-cmd");
|
parser.setOption("finish-cmd");
|
||||||
|
parser.setOption("finish-dir");
|
||||||
parser.setOption("script");
|
parser.setOption("script");
|
||||||
parser.setOption("wait");
|
parser.setOption("wait");
|
||||||
parser.setOption("mode");
|
parser.setOption("mode");
|
||||||
@ -74,6 +75,10 @@ void UpdaterOptions::parse(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
finishCmd = parser.getValue("finish-cmd");
|
finishCmd = parser.getValue("finish-cmd");
|
||||||
}
|
}
|
||||||
|
if (parser.getValue("finish-dir"))
|
||||||
|
{
|
||||||
|
finishDir = parser.getValue("finish-dir");
|
||||||
|
}
|
||||||
|
|
||||||
showVersion = parser.getFlag("version");
|
showVersion = parser.getFlag("version");
|
||||||
forceElevated = parser.getFlag("force-elevated");
|
forceElevated = parser.getFlag("force-elevated");
|
||||||
|
@ -15,6 +15,7 @@ class UpdaterOptions
|
|||||||
std::string packageDir;
|
std::string packageDir;
|
||||||
std::string scriptPath;
|
std::string scriptPath;
|
||||||
std::string finishCmd;
|
std::string finishCmd;
|
||||||
|
std::string finishDir;
|
||||||
PLATFORM_PID waitPid;
|
PLATFORM_PID waitPid;
|
||||||
std::string logFile;
|
std::string logFile;
|
||||||
bool showVersion;
|
bool showVersion;
|
||||||
|
@ -138,7 +138,8 @@ int main(int argc, char** argv)
|
|||||||
+ ", wait-pid: " + intToStr(options.waitPid)
|
+ ", wait-pid: " + intToStr(options.waitPid)
|
||||||
+ ", script-path: " + options.scriptPath
|
+ ", script-path: " + options.scriptPath
|
||||||
+ ", mode: " + intToStr(options.mode)
|
+ ", mode: " + intToStr(options.mode)
|
||||||
+ ", finish-cmd: " + options.finishCmd);
|
+ ", finish-cmd: " + options.finishCmd
|
||||||
|
+ ", finish-dir: " + options.finishDir);
|
||||||
|
|
||||||
installer.setMode(options.mode);
|
installer.setMode(options.mode);
|
||||||
installer.setInstallDir(options.installDir);
|
installer.setInstallDir(options.installDir);
|
||||||
@ -148,6 +149,7 @@ int main(int argc, char** argv)
|
|||||||
installer.setForceElevated(options.forceElevated);
|
installer.setForceElevated(options.forceElevated);
|
||||||
installer.setAutoClose(options.autoClose);
|
installer.setAutoClose(options.autoClose);
|
||||||
installer.setFinishCmd(options.finishCmd);
|
installer.setFinishCmd(options.finishCmd);
|
||||||
|
installer.setFinishDir(options.finishDir);
|
||||||
installer.setDryRun(options.dryRun);
|
installer.setDryRun(options.dryRun);
|
||||||
|
|
||||||
if (options.mode == UpdateInstaller::Main)
|
if (options.mode == UpdateInstaller::Main)
|
||||||
|
@ -44,5 +44,4 @@ macro(ADD_UPDATER_TEST CLASS)
|
|||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
add_updater_test(TestParseScript)
|
add_updater_test(TestParseScript)
|
||||||
add_updater_test(TestUpdaterOptions)
|
|
||||||
add_updater_test(TestFileUtils)
|
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();
|
|
||||||
};
|
|
||||||
|
|
@ -15,7 +15,6 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
MMC_DIR="$(dirname "$(readlink -f "$0")")"
|
MMC_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
cd "${MMC_DIR}"
|
|
||||||
echo "MultiMC Dir: ${MMC_DIR}"
|
echo "MultiMC Dir: ${MMC_DIR}"
|
||||||
|
|
||||||
# Set up env
|
# Set up env
|
||||||
|
@ -39,7 +39,7 @@ int main(int argc, char *argv[]) \
|
|||||||
{ \
|
{ \
|
||||||
char *argv_[] = { argv[0] _MMC_EXTRA_ARGV }; \
|
char *argv_[] = { argv[0] _MMC_EXTRA_ARGV }; \
|
||||||
int argc_ = 1 + _MMC_EXTRA_ARGC; \
|
int argc_ = 1 + _MMC_EXTRA_ARGC; \
|
||||||
MultiMC app(argc_, argv_/*, QDir::temp().absoluteFilePath("MultiMC_Test")*/); \
|
MultiMC app(argc_, argv_, true); \
|
||||||
app.setAttribute(Qt::AA_Use96Dpi, true); \
|
app.setAttribute(Qt::AA_Use96Dpi, true); \
|
||||||
TestObject tc; \
|
TestObject tc; \
|
||||||
return QTest::qExec(&tc, argc, argv); \
|
return QTest::qExec(&tc, argc, argv); \
|
||||||
|
@ -254,7 +254,7 @@ slots:
|
|||||||
pathOrig = path = "MultiMC.app/Foo/Bar/Baz";
|
pathOrig = path = "MultiMC.app/Foo/Bar/Baz";
|
||||||
qDebug() << "Proper OSX path: " << path;
|
qDebug() << "Proper OSX path: " << path;
|
||||||
result = DownloadUpdateTask::fixPathForOSX(path);
|
result = DownloadUpdateTask::fixPathForOSX(path);
|
||||||
QCOMPARE(path, QString("../../Foo/Bar/Baz"));
|
QCOMPARE(path, QString("Foo/Bar/Baz"));
|
||||||
QCOMPARE(result, true);
|
QCOMPARE(result, true);
|
||||||
|
|
||||||
// Bad OSX path
|
// Bad OSX path
|
||||||
|
Loading…
Reference in New Issue
Block a user