aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2013-12-11 12:17:39 +0100
committerChristian Kandeler <christian.kandeler@digia.com>2013-12-11 15:55:16 +0100
commitf8f985af535712e051be28883aef9199cde3b022 (patch)
tree86e8eadf31c96c6d54cd839f6473bd9e5c11f99f
parent62d9a36e64b0e83466c2bdbdd313578d300cd497 (diff)
Fix installation for read-only files.
On Windows, we must explicitly add write permissions to the target file before removing it, as the operation will fail if the file is not writable. Task-number: QBS-475 Change-Id: Ide40cc4310e327265b0a5c08f4935866762797b9 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r--src/lib/tools/fileinfo.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/lib/tools/fileinfo.cpp b/src/lib/tools/fileinfo.cpp
index 6e413b1e9..bcaf33bde 100644
--- a/src/lib/tools/fileinfo.cpp
+++ b/src/lib/tools/fileinfo.cpp
@@ -326,12 +326,16 @@ bool removeFileRecursion(const QFileInfo &f, QString *errorMessage)
arg(QDir::toNativeSeparators(f.absoluteFilePath())));
return false;
}
- } else if (!QFile::remove(f.absoluteFilePath())) {
- if (!errorMessage->isEmpty())
- errorMessage->append(QLatin1Char('\n'));
- errorMessage->append(Tr::tr("The file %1 could not be deleted.").
- arg(QDir::toNativeSeparators(f.absoluteFilePath())));
- return false;
+ } else {
+ QFile file(f.absoluteFilePath());
+ file.setPermissions(f.permissions() | QFile::WriteUser);
+ if (!file.remove()) {
+ if (!errorMessage->isEmpty())
+ errorMessage->append(QLatin1Char('\n'));
+ errorMessage->append(Tr::tr("The file %1 could not be deleted.").
+ arg(QDir::toNativeSeparators(f.absoluteFilePath())));
+ return false;
+ }
}
return true;
}
@@ -452,9 +456,12 @@ bool copyFileRecursion(const QString &srcFilePath, const QString &tgtFilePath,
return true;
QFile file(srcFilePath);
QFile targetFile(tgtFilePath);
- if (targetFile.exists() && !targetFile.remove()) {
- *errorMessage = Tr::tr("Could not remove file '%1'. %2")
- .arg(QDir::toNativeSeparators(tgtFilePath), targetFile.errorString());
+ if (targetFile.exists()) {
+ targetFile.setPermissions(targetFile.permissions() | QFile::WriteUser);
+ if (!targetFile.remove()) {
+ *errorMessage = Tr::tr("Could not remove file '%1'. %2")
+ .arg(QDir::toNativeSeparators(tgtFilePath), targetFile.errorString());
+ }
}
if (!file.copy(tgtFilePath)) {
*errorMessage = Tr::tr("Could not copy file '%1' to '%2'. %3")