diff options
author | Andy Shaw <andy.shaw@qt.io> | 2017-08-18 12:35:27 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2017-09-13 12:45:35 +0000 |
commit | 793f0ddec2a1ac04360adf468197fe76f75051d9 (patch) | |
tree | b192edf9008662664ad2a6b358a8493480f5e40f /qmake | |
parent | 1d5e55c2a34b0d5693a148075e3840aed9cab8b7 (diff) |
Win: Handle installation of read-only target files correctly
When the source file is read-only then it would copy the file with that
attribute set when it is installed. However this will cause a problem
if it is installed a second time. Therefore the read-only attribute
needs to be manually reset before installing and again before touching
the file. Once the process is done then it is set back to be read-only
to preserve the state of the original.
Change-Id: I1c01f418ef3c9bd434acd2c2b8ee695544d7bb35
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Diffstat (limited to 'qmake')
-rw-r--r-- | qmake/main.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/qmake/main.cpp b/qmake/main.cpp index 13b18d018a..85709dc9bf 100644 --- a/qmake/main.cpp +++ b/qmake/main.cpp @@ -245,9 +245,15 @@ static int doLink(int argc, char **argv) static int installFile(const QString &source, const QString &target, bool exe = false) { QFile sourceFile(source); - - QFile::remove(target); - QDir::root().mkpath(QFileInfo(target).absolutePath()); + QFile targetFile(target); + if (targetFile.exists()) { +#ifdef Q_OS_WIN + targetFile.setPermissions(targetFile.permissions() | QFile::WriteUser); +#endif + QFile::remove(target); + } else { + QDir::root().mkpath(QFileInfo(target).absolutePath()); + } if (!sourceFile.copy(target)) { fprintf(stderr, "Error copying %s to %s: %s\n", source.toLatin1().constData(), qPrintable(target), qPrintable(sourceFile.errorString())); @@ -255,7 +261,6 @@ static int installFile(const QString &source, const QString &target, bool exe = } if (exe) { - QFile targetFile(target); if (!targetFile.setPermissions(sourceFile.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeUser | QFileDevice::ExeGroup | QFileDevice::ExeOther)) { fprintf(stderr, "Error setting execute permissions on %s: %s\n", @@ -266,10 +271,20 @@ static int installFile(const QString &source, const QString &target, bool exe = // Copy file times QString error; +#ifdef Q_OS_WIN + const QFile::Permissions permissions = targetFile.permissions(); + const bool readOnly = !(permissions & QFile::WriteUser); + if (readOnly) + targetFile.setPermissions(permissions | QFile::WriteUser); +#endif if (!IoUtils::touchFile(target, sourceFile.fileName(), &error)) { fprintf(stderr, "%s", qPrintable(error)); return 3; } +#ifdef Q_OS_WIN + if (readOnly) + targetFile.setPermissions(permissions); +#endif return 0; } |