summaryrefslogtreecommitdiffstats
path: root/tests/shared
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2021-05-31 15:43:45 +0200
committerKarsten Heimrich <karsten.heimrich@qt.io>2021-06-02 23:02:45 +0200
commitebacf425614ffd2c38e4902a122ff4a63e277706 (patch)
treef5e3ab12471161a9d453c04f75a7e30a902dc519 /tests/shared
parent70cc0885f9e790dda16f2655e8c524179c3c6202 (diff)
Move createSymbolicLink() to the shared header
Change-Id: I737f521791faf07d704e15d36d57444b3187ba9d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/shared')
-rw-r--r--tests/shared/filesystem.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/shared/filesystem.h b/tests/shared/filesystem.h
index 03f2bb42fd..20bf9c06e3 100644
--- a/tests/shared/filesystem.h
+++ b/tests/shared/filesystem.h
@@ -46,6 +46,9 @@
#ifndef FSCTL_SET_REPARSE_POINT
#define FSCTL_SET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
#endif
+#ifndef SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE // MinGW
+#define SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE (0x2)
+#endif
#endif
// QTemporaryDir-based helper class for creating file-system hierarchies and cleaning up.
@@ -80,6 +83,27 @@ public:
}
#if defined(Q_OS_WIN)
+ static DWORD createSymbolicLink(const QString &symLinkName, const QString &target,
+ QString *errorMessage)
+ {
+ DWORD result = ERROR_SUCCESS;
+ const QString nativeSymLinkName = QDir::toNativeSeparators(symLinkName);
+ const QString nativeTarget = QDir::toNativeSeparators(target);
+ DWORD flags = 0;
+ if (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 14972))
+ flags |= SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
+ if (QFileInfo(target).isDir())
+ flags |= SYMBOLIC_LINK_FLAG_DIRECTORY;
+ if (CreateSymbolicLink(reinterpret_cast<const wchar_t*>(nativeSymLinkName.utf16()),
+ reinterpret_cast<const wchar_t*>(nativeTarget.utf16()), flags) == FALSE) {
+ result = GetLastError();
+ QTextStream(errorMessage) << "CreateSymbolicLink(" << nativeSymLinkName << ", "
+ << nativeTarget << ", 0x" << Qt::hex << flags << Qt::dec << ") failed with error " << result
+ << ": " << qt_error_string(int(result));
+ }
+ return result;
+ }
+
static DWORD createNtfsJunction(QString target, QString linkName, QString *errorMessage)
{
typedef struct {