summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrerich Raabe <raabe@froglogic.com>2015-11-19 12:26:20 +0100
committerKarsten Heimrich <karsten.heimrich@theqtcompany.com>2015-12-08 13:06:49 +0000
commit5e28f85a886e1e28edc0370f15b777bbf2b2a557 (patch)
treed1cd5c2d1e9b627f7b2f5b0caf621a19a94f93e8
parent1963986ba756faca9a33d727563be1a5962191a8 (diff)
Fixed running binarycreator if the temporary directory name contains spaces
The binarycreator program fails to generate an archive if the temporary directory name contains spaces. This is not uncommon on Windows since the temporary directory is beneath the home directory, e.g. C:\Users\<username>\AppData\Local\Temp. If the user name contains spaces (as it does in my case, the user name is "Frerich Raabe") binarycreator fails with [64] Warning: QFile::remove: Empty or null file name (C:\Qt\MSVC12\5.5.0-src\qtbase\src\corelib\io\qfile.cpp:498, bool __thiscall QFile::remove(void)) Caught exception: Cannot create archive "C:\Users\Frerich": internal code: E_FAIL This was caused by createArchive() assembling a command line without escaping either the 'target' or any of the 'sources' values. Instead of adding escaping only to split the command line again, let's drop the approach of constructing a command and then splitting it completely. Instead, let's build an array of arguments right away. Change-Id: I284c1b5a27e9edd3717243ea7979149ab2033d64 Task-number: QTIFW-787 Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>
-rw-r--r--src/libs/installer/lib7z_facade.cpp27
-rw-r--r--tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp26
2 files changed, 38 insertions, 15 deletions
diff --git a/src/libs/installer/lib7z_facade.cpp b/src/libs/installer/lib7z_facade.cpp
index 458bf5770..a5a038d91 100644
--- a/src/libs/installer/lib7z_facade.cpp
+++ b/src/libs/installer/lib7z_facade.cpp
@@ -46,8 +46,6 @@
# include "StdAfx.h"
#endif
-#include <Common/CommandLineParser.h>
-
#include <7zCrc.h>
#include <7zip/Archive/IArchive.h>
@@ -930,21 +928,22 @@ void createArchive(const QString &archive, const QStringList &sources, QTmpFile
if (mode == QTmpFile::Yes)
target = createTmp7z();
- const UString command = QString2UString(
- // (mode: add) (type: 7z) (time: modified|creation|access) (threads: multi-threaded)
- QLatin1String("a -t7z -mtm=on -mtc=on -mta=on -mmt=on ")
-#ifdef Q_OS_WIN
- + QLatin1String("-sccUTF-8 ") // (files: case-sensitive|UTF8)
-#endif
- + QString::fromLatin1("-mx=%1 ").arg(int(level)) // (compression: level)
- + QDir::toNativeSeparators(target) + QLatin1Char(' ')
- + QDir::toNativeSeparators(sources.join(QLatin1Char(' ')))
- );
-
CArcCmdLineOptions options;
try {
UStringVector commandStrings;
- NCommandLineParser::SplitCommandLine(command, commandStrings);
+ commandStrings.Add(L"a"); // mode: add
+ commandStrings.Add(L"-t7z"); // type: 7z
+ commandStrings.Add(L"-mtm=on"); // time: modeifier|creation|access
+ commandStrings.Add(L"-mtc=on");
+ commandStrings.Add(L"-mta=on");
+ commandStrings.Add(L"-mmt=on"); // threads: multi-threaded
+#ifdef Q_OS_WIN
+ commandStrings.Add(L"-sccUTF-8"); // files: case-sensitive|UTF8
+#endif
+ commandStrings.Add(QString2UString(QString::fromLatin1("-mx=%1").arg(int(level)))); // compression: level
+ commandStrings.Add(QString2UString(QDir::toNativeSeparators(target)));
+ foreach (const QString &source, sources)
+ commandStrings.Add(QString2UString(source));
CArcCmdLineParser parser;
parser.Parse1(commandStrings, options);
diff --git a/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp b/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp
index 7dde7e555..514df2a2e 100644
--- a/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp
+++ b/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp
@@ -121,6 +121,27 @@ private slots:
} catch (...) {
QFAIL("Unexpected error during create archive.");
}
+
+ try {
+ const QString path1 = tempSourceFile(
+ "Source File 1.",
+ QDir::tempPath() + "/temp file with spaces.XXXXXX"
+ );
+ const QString path2 = tempSourceFile(
+ "Source File 2.",
+ QDir::tempPath() + "/temp file with spaces.XXXXXX"
+ );
+
+ QTemporaryFile target(QDir::tempPath() + "/target file with spaces.XXXXXX");
+ QVERIFY(target.open());
+ Lib7z::createArchive(&target, QStringList() << path1 << path2);
+ QCOMPARE(Lib7z::listArchive(&target).count(), 2);
+ } catch (const Lib7z::SevenZipException& e) {
+ QFAIL(e.message().toUtf8());
+ } catch (...) {
+ QFAIL("Unexpected error during create archive.");
+ }
+
}
void testExtractArchive()
@@ -139,9 +160,12 @@ private slots:
}
private:
- QString tempSourceFile(const QByteArray &data)
+ QString tempSourceFile(const QByteArray &data, const QString &templateName = QString())
{
QTemporaryFile source;
+ if (!templateName.isEmpty()) {
+ source.setFileTemplate(templateName);
+ }
source.open();
source.write(data);
source.setAutoRemove(false);