From 81685b0ac08e5ff454a6af9a8d98bd4a63b247dd Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 2 Aug 2023 22:19:39 -0700 Subject: [PATCH] QEXTRACTTESTDATA: include the errorString() in case of failure In case we fail to copy or set the permissions, get the error string from QFile. This necessitated fixing QFile so it would copy the error from QTemporaryFile in case the latter failed to open. Drive-by use %ls to avoid going through the locale codec in QtTest. Change-Id: Ifbf974a4d10745b099b1fffd1777c7e6e00c25af Reviewed-by: Fabian Kosmale Reviewed-by: Qt CI Bot Reviewed-by: Edward Welbourne --- src/corelib/io/qfile.cpp | 2 +- src/testlib/qtestcase.cpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index ec67ca6f48..e136241630 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -781,9 +781,9 @@ QFile::copy(const QString &newName) } #endif if (error) { + d->setError(QFile::CopyError, tr("Cannot open for output: %1").arg(out.errorString())); out.close(); close(); - d->setError(QFile::CopyError, tr("Cannot open for output: %1").arg(out.errorString())); } else { if (!d->engine()->cloneTo(out.d_func()->engine())) { char block[4096]; diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 38108729cc..cc687fe369 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2702,12 +2702,17 @@ QSharedPointer QTest::qExtractTestData(const QString &dirName) const QString destination = dataPath + u'/' + QStringView{fileInfo.filePath()}.mid(resourcePath.size()); QFileInfo destinationFileInfo(destination); QDir().mkpath(destinationFileInfo.path()); - if (!QFile::copy(fileInfo.filePath(), destination)) { - qWarning("Failed to copy '%s'.", qPrintable(fileInfo.filePath())); + QFile file(fileInfo.filePath()); + if (!file.copy(destination)) { + qWarning("Failed to copy '%ls': %ls.", qUtf16Printable(fileInfo.filePath()), + qUtf16Printable(file.errorString())); return result; } - if (!QFile::setPermissions(destination, QFile::ReadUser | QFile::WriteUser | QFile::ReadGroup)) { - qWarning("Failed to set permissions on '%s'.", qPrintable(destination)); + + file.setFileName(destination); + if (!file.setPermissions(QFile::ReadUser | QFile::WriteUser | QFile::ReadGroup)) { + qWarning("Failed to set permissions on '%ls': %ls.", qUtf16Printable(destination), + qUtf16Printable(file.errorString())); return result; } }