From b2bcc76c4ff20c1133390ded48d8b8c9b86b0b5c Mon Sep 17 00:00:00 2001 From: Vlad Lipskiy Date: Fri, 2 Aug 2019 15:25:24 +0300 Subject: [PATCH] Fixes "qmake -install qinstall" on folders with read-only files This commit returns the removed procedure of ensuring user write permissions on files before touching them on Windows. --- qmake/main.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/qmake/main.cpp b/qmake/main.cpp index a598296898..6e44cd5544 100644 --- a/qmake/main.cpp +++ b/qmake/main.cpp @@ -242,6 +242,26 @@ static int doLink(int argc, char **argv) #endif +static bool copyFileTimes(QFile &targetFile, const QFile &sourceFile, QString *errorString) +{ +#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(targetFile.fileName(), sourceFile.fileName(), errorString)) { + return false; + } +#ifdef Q_OS_WIN + if (readOnly) { + targetFile.setPermissions(permissions); + } +#endif + return true; +} + static int installFile(const QString &source, const QString &target, bool exe = false, bool preservePermissions = false) { @@ -276,9 +296,8 @@ static int installFile(const QString &source, const QString &target, bool exe = return 3; } - // Copy file times QString error; - if (!IoUtils::touchFile(target, sourceFile.fileName(), &error)) { + if (!copyFileTimes(targetFile, sourceFile, &error)) { fprintf(stderr, "%s", qPrintable(error)); return 3; } -- 2.21.0.windows.1