forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -294,23 +294,51 @@ QString TemporaryDir::createFile(const QByteArray &relativePath, const QByteArra
|
|||||||
return filePath;
|
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)
|
TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath)
|
||||||
{
|
{
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!sourceDirPath.isEmpty()) {
|
if (sourceDirPath.isEmpty())
|
||||||
QFileInfo fi(sourceDirPath);
|
return;
|
||||||
if (!fi.exists() || !fi.isReadable()) {
|
|
||||||
m_isValid = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Utils::FileUtils::copyRecursively(Utils::FileName::fromString(sourceDirPath),
|
QFileInfo fi(sourceDirPath);
|
||||||
Utils::FileName::fromString(path()))) {
|
if (!fi.exists() || !fi.isReadable()) {
|
||||||
m_isValid = false;
|
m_isValid = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString errorMessage;
|
||||||
|
if (!copyRecursively(sourceDirPath, path(), &errorMessage)) {
|
||||||
|
QWARN(qPrintable(errorMessage));
|
||||||
|
m_isValid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user