aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cpptools/cpptoolstestcase.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-07-01 11:47:17 +0200
committerNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-07-02 15:28:11 +0000
commit8cb7d68cf6664fe721828648bc8ed2bb621c8a1b (patch)
tree9baf68b1aff01c0197ab46b8f593480dd8cdd05a /src/plugins/cpptools/cpptoolstestcase.cpp
parentdace404ca39c11b04c7d959726cacca7e6de55c8 (diff)
CppTools: Tests: Fix QTemporaryDir warning on Windows
...coming from TemporaryCopiedDir. The warning was: QTemporaryDir: Unable to remove <some path> most likely due to the presence of read-only files. It occurred for plugin tests (e.g ClangCodeModel) that used a Qt resource path as source for TemporaryCopiedDir. Copying a qrc file makes it read-only, see also QTBUG-17163. Therefore, explicitly add the write permission. Change-Id: Idc04acd4844c5bc20e9b3de1efc78da3b06ac97c Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com> Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Diffstat (limited to 'src/plugins/cpptools/cpptoolstestcase.cpp')
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.cpp50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp
index fa6bed8b511..8d2a3684a0c 100644
--- a/src/plugins/cpptools/cpptoolstestcase.cpp
+++ b/src/plugins/cpptools/cpptoolstestcase.cpp
@@ -294,23 +294,51 @@ QString TemporaryDir::createFile(const QByteArray &relativePath, const QByteArra
return filePath;
}
+static bool copyRecursively(const QString &sourceDirPath,
+ const QString &targetDirPath,
+ QString *error)
+{
+ auto copyHelper = [](QFileInfo sourceInfo, QFileInfo targetInfo, QString *error) -> bool {
+ const QString sourcePath = sourceInfo.absoluteFilePath();
+ const QString targetPath = targetInfo.absoluteFilePath();
+ if (!QFile::copy(sourcePath, targetPath)) {
+ if (error) {
+ *error = QString::fromLatin1("copyRecursively() failed: \"%1\" to \"%2\".")
+ .arg(sourcePath, targetPath);
+ }
+ return false;
+ }
+
+ // Copied files from Qt resources are read-only. Make them writable
+ // so that their parent directory can be removed without warnings.
+ QFile file(targetPath);
+ return file.setPermissions(file.permissions() | QFile::WriteUser);
+ };
+
+ return Utils::FileUtils::copyRecursively(Utils::FileName::fromString(sourceDirPath),
+ Utils::FileName::fromString(targetDirPath),
+ error,
+ copyHelper);
+}
+
TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath)
{
if (!m_isValid)
return;
- if (!sourceDirPath.isEmpty()) {
- QFileInfo fi(sourceDirPath);
- if (!fi.exists() || !fi.isReadable()) {
- m_isValid = false;
- return;
- }
+ if (sourceDirPath.isEmpty())
+ return;
- if (!Utils::FileUtils::copyRecursively(Utils::FileName::fromString(sourceDirPath),
- Utils::FileName::fromString(path()))) {
- m_isValid = false;
- return;
- }
+ QFileInfo fi(sourceDirPath);
+ if (!fi.exists() || !fi.isReadable()) {
+ m_isValid = false;
+ return;
+ }
+
+ QString errorMessage;
+ if (!copyRecursively(sourceDirPath, path(), &errorMessage)) {
+ QWARN(qPrintable(errorMessage));
+ m_isValid = false;
}
}