mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2024-11-22 20:01:20 +00:00
Interpret the CurrentDir=$DIR argument on the command line as being relative to the directory containing the main application binary
Mendeley Desktop <= 1.0 clients set CurrentDir to the directory containing the main application binary rather than the root of the install directory. Change the parsing in UpdaterOptions and adjust the test accordingly.
This commit is contained in:
parent
e835036e41
commit
b5edffc0b6
4 changed files with 69 additions and 2 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "minizip/unzip.h"
|
||||
|
||||
|
@ -139,6 +140,23 @@ void FileUtils::extractFromZip(const char* zipFilePath, const char* src, const c
|
|||
unzClose(zipFile);
|
||||
}
|
||||
|
||||
void FileUtils::mkpath(const char* dir) throw (IOException)
|
||||
{
|
||||
std::string currentPath;
|
||||
std::istringstream stream(dir);
|
||||
while (!stream.eof())
|
||||
{
|
||||
std::string segment;
|
||||
std::getline(stream,segment,'/');
|
||||
currentPath += segment;
|
||||
if (!currentPath.empty() && !fileExists(currentPath.c_str()))
|
||||
{
|
||||
mkdir(currentPath.c_str());
|
||||
}
|
||||
currentPath += '/';
|
||||
}
|
||||
}
|
||||
|
||||
void FileUtils::mkdir(const char* dir) throw (IOException)
|
||||
{
|
||||
#ifdef PLATFORM_UNIX
|
||||
|
|
|
@ -70,6 +70,11 @@ class FileUtils
|
|||
static void createSymLink(const char* link, const char* target) throw (IOException);
|
||||
static void touch(const char* path) throw (IOException);
|
||||
|
||||
/** Create all the directories in @p path which do not yet exist.
|
||||
* @p path may be relative or absolute.
|
||||
*/
|
||||
static void mkpath(const char* path) throw (IOException);
|
||||
|
||||
/** Returns the file name part of a file path, including the extension. */
|
||||
static std::string fileName(const char* path);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "Log.h"
|
||||
#include "AnyOption/anyoption.h"
|
||||
#include "FileUtils.h"
|
||||
#include "Platform.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
|
@ -47,6 +48,10 @@ void UpdaterOptions::parseOldFormatArg(const std::string& arg, std::string* key,
|
|||
}
|
||||
}
|
||||
|
||||
// this is a compatibility function to allow the updater binary
|
||||
// to be involved by legacy versions of Mendeley Desktop
|
||||
// which used a different syntax for the updater's command-line
|
||||
// arguments
|
||||
void UpdaterOptions::parseOldFormatArgs(int argc, char** argv)
|
||||
{
|
||||
for (int i=0; i < argc; i++)
|
||||
|
@ -58,7 +63,22 @@ void UpdaterOptions::parseOldFormatArgs(int argc, char** argv)
|
|||
|
||||
if (key == "CurrentDir")
|
||||
{
|
||||
// CurrentDir is the directory containing the main application
|
||||
// binary. On Mac and Linux this differs from the root of
|
||||
// the installation directory
|
||||
|
||||
#ifdef PLATFORM_LINUX
|
||||
// the main binary is in lib/mendeleydesktop/libexec,
|
||||
// go up 3 levels
|
||||
installDir = FileUtils::canonicalPath((value + "/../../../").c_str());
|
||||
#elif defined(PLATFORM_MAC)
|
||||
// the main binary is in Contents/MacOS,
|
||||
// go up 2 levels
|
||||
installDir = FileUtils::canonicalPath((value + "/../../").c_str());
|
||||
#elif defined(PLATFORM_WINDOWS)
|
||||
// the main binary is in the root of the install directory
|
||||
installDir = value;
|
||||
#endif
|
||||
}
|
||||
else if (key == "TempDir")
|
||||
{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "TestUpdaterOptions.h"
|
||||
|
||||
#include "FileUtils.h"
|
||||
#include "Platform.h"
|
||||
#include "TestUtils.h"
|
||||
#include "UpdaterOptions.h"
|
||||
|
||||
|
@ -11,7 +13,25 @@ void TestUpdaterOptions::testOldFormatArgs()
|
|||
const int argc = 6;
|
||||
char* argv[argc];
|
||||
argv[0] = strdup("updater");
|
||||
argv[1] = strdup("CurrentDir=/path/to/app");
|
||||
|
||||
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");
|
||||
|
@ -21,7 +41,11 @@ void TestUpdaterOptions::testOldFormatArgs()
|
|||
options.parse(argc,argv);
|
||||
|
||||
TEST_COMPARE(options.mode,UpdateInstaller::Setup);
|
||||
TEST_COMPARE(options.installDir,"/path/to/app");
|
||||
#ifdef PLATFORM_UNIX
|
||||
TEST_COMPARE(options.installDir,"/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);
|
||||
|
|
Loading…
Reference in a new issue