From 935562a77ba5f4dc90960ae5685c461efc83c0ee Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 18 Oct 2023 20:54:37 -0700 Subject: [PATCH] QTemporaryFile(Name): don't make the path absolute on generation I need to use QTemporaryFileName in a context where absolute paths are not allowed because they change the behavior of the system call (the -at() POSIX system calls); see next commit. This required a fix to a seemingly unrelated test, which depended on the absolute path, because QPluginLoader and QLibrary assume a file name with no path components imply "search the standard places". [ChangeLog][Important Behavior Changes][QTemporaryFile] This class will now return relative file paths in fileName() if the file template was also a relative path (it used to always return an absolute path). The temporary files are still created in the same directory; this change only affects the length of the path the function returns. Change-Id: I79e700614d034281bf55fffd178f65f2b3d602d8 Reviewed-by: Edward Welbourne --- src/corelib/io/qtemporaryfile.cpp | 5 ++--- .../auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index a98256c1f42..ff6a514fc9c 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -70,9 +70,8 @@ QTemporaryFileName::QTemporaryFileName(const QString &templateName) qfilename.append(".XXXXXX"_L1); // "Nativify" :-) - QFileSystemEntry::NativePath filename = QFileSystemEngine::absoluteName( - QFileSystemEntry(qfilename, QFileSystemEntry::FromInternalPath())) - .nativeFilePath(); + QFileSystemEntry::NativePath filename = + QFileSystemEntry(QDir::cleanPath(qfilename)).nativeFilePath(); // Find mask in native path phPos = filename.size(); diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp index bb6ecb45f41..cc8ed2db6ea 100644 --- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp @@ -16,6 +16,8 @@ # include #endif +using namespace Qt::StringLiterals; + // Helper macros to let us know if some suffixes are valid #define bundle_VALID false #define dylib_VALID false @@ -128,7 +130,7 @@ static std::unique_ptr patchElf(const QString &source, ElfPatche const char *basename = QTest::currentDataTag(); if (!basename) basename = QTest::currentTestFunction(); - tmplib.reset(new QTemporaryFile(basename + QString(".XXXXXX" SUFFIX))); + tmplib.reset(new QTemporaryFile(QDir::currentPath() + u'/' + basename + u".XXXXXX" SUFFIX ""_s)); QVERIFY2(tmplib->open(), qPrintable(tmplib->errorString())); // sanity-check