diff options
author | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2019-10-07 17:53:40 +0300 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2019-10-10 12:59:52 +0000 |
commit | 62eeab668c239a4a8a8ae4058d3f378464c2def2 (patch) | |
tree | 173ec4972643022c1aa92fe83b40be6190c44293 | |
parent | 63723d0d7405cf6ab56347e6efac9cecc0309036 (diff) |
Fix CreateLink operation destination string formatting on Windows
- Fix string formatting syntax in createJunction() method.
- Calculate destination directory string length in bytes rather than
characters count.
- Make minor alterations to operation usage documentation.
Task-number: QTIFW-1443
Change-Id: Ia7f6525c865a3e8a6da5376059111c1ef87353ac
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
-rw-r--r-- | doc/operations.qdoc | 4 | ||||
-rw-r--r-- | src/libs/installer/link.cpp | 11 |
2 files changed, 9 insertions, 6 deletions
diff --git a/doc/operations.qdoc b/doc/operations.qdoc index 98906ab9c..762d12330 100644 --- a/doc/operations.qdoc +++ b/doc/operations.qdoc @@ -205,8 +205,8 @@ \row \li CreateLink \li "CreateLink" \c linkPath \c targetPath - \li Creates a link from the location specified by \c linkPath to - the location specified by \c targetPath. + \li Creates a link in the location specified by \c linkPath that + points to the location specified by \c targetPath. \row \li CreateLocalRepository \li "CreateLocalRepository" \c binaryPath \c repoPath diff --git a/src/libs/installer/link.cpp b/src/libs/installer/link.cpp index 62ba06cb2..0c79ec4c9 100644 --- a/src/libs/installer/link.cpp +++ b/src/libs/installer/link.cpp @@ -146,9 +146,12 @@ Link createJunction(const QString &linkPath, const QString &targetPath) return Link(linkPath); } - const QString szDestDir = QString::fromLatin1("\\??\\").arg(targetPath).replace(QLatin1Char('/'), + const QString szDestDir = QString::fromLatin1("\\??\\%1").arg(targetPath).replace(QLatin1Char('/'), QLatin1Char('\\')); + // Get string length in bytes, not in characters count + const size_t destDirBytes = szDestDir.size() * sizeof(ushort); + // Allocates a block of memory for an array of num elements(1) and initializes all its bits to zero. REPARSE_DATA_BUFFER* reparseStructData = (REPARSE_DATA_BUFFER*)calloc(1, MAXIMUM_REPARSE_DATA_BUFFER_SIZE); @@ -156,11 +159,11 @@ Link createJunction(const QString &linkPath, const QString &targetPath) reparseStructData->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT; reparseStructData->MountPointReparseBuffer.PrintNameLength = 0; reparseStructData->MountPointReparseBuffer.SubstituteNameOffset = 0; - reparseStructData->MountPointReparseBuffer.SubstituteNameLength = szDestDir.length(); - reparseStructData->MountPointReparseBuffer.PrintNameOffset = szDestDir.length() + sizeof(WCHAR); + reparseStructData->MountPointReparseBuffer.SubstituteNameLength = destDirBytes; + reparseStructData->MountPointReparseBuffer.PrintNameOffset = destDirBytes + sizeof(WCHAR); uint spaceAfterGeneralData = sizeof(USHORT) * 5 + sizeof(WCHAR); //should be 12 - reparseStructData->ReparseDataLength = szDestDir.length() + spaceAfterGeneralData; + reparseStructData->ReparseDataLength = destDirBytes + spaceAfterGeneralData; #ifndef Q_CC_MINGW StringCchCopy(reparseStructData->MountPointReparseBuffer.PathBuffer, 1024, (wchar_t*)szDestDir.utf16()); |