Skip to content

Commit

Permalink
Fix qinstall on Windows for directories containing read-only files
Browse files Browse the repository at this point in the history
Initial patch by: Vlad Lipskiy <[email protected]>

Fixes: QTBUG-77299
Change-Id: I803b809d1f23d844252b701cb070f6e4ba34eca1
Reviewed-by: Oliver Wolff <[email protected]>
  • Loading branch information
jobor committed Aug 15, 2019
1 parent 0d024bd commit 31e0d17
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
42 changes: 36 additions & 6 deletions qmake/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,39 @@ static int doLink(int argc, char **argv)

#endif

static bool setFilePermissions(QFile &file, QFileDevice::Permissions permissions)
{
if (file.setPermissions(permissions))
return true;
fprintf(stderr, "Error setting permissions on %s: %s\n",
qPrintable(file.fileName()), qPrintable(file.errorString()));
return false;
}

static bool copyFileTimes(QFile &targetFile, const QString &sourceFilePath,
bool mustEnsureWritability, QString *errorString)
{
#ifdef Q_OS_WIN
bool mustRestorePermissions = false;
QFileDevice::Permissions targetPermissions;
if (mustEnsureWritability) {
targetPermissions = targetFile.permissions();
if (!targetPermissions.testFlag(QFileDevice::WriteUser)) {
mustRestorePermissions = true;
if (!setFilePermissions(targetFile, targetPermissions | QFileDevice::WriteUser))
return false;
}
}
#endif
if (!IoUtils::touchFile(targetFile.fileName(), sourceFilePath, errorString))
return false;
#ifdef Q_OS_WIN
if (mustRestorePermissions && !setFilePermissions(targetFile, targetPermissions))
return false;
#endif
return true;
}

static int installFile(const QString &source, const QString &target, bool exe = false,
bool preservePermissions = false)
{
Expand Down Expand Up @@ -270,18 +303,15 @@ static int installFile(const QString &source, const QString &target, bool exe =
targetPermissions |= QFileDevice::ExeOwner | QFileDevice::ExeUser |
QFileDevice::ExeGroup | QFileDevice::ExeOther;
}
if (!targetFile.setPermissions(targetPermissions)) {
fprintf(stderr, "Error setting permissions on %s: %s\n",
qPrintable(target), qPrintable(targetFile.errorString()));
if (!setFilePermissions(targetFile, targetPermissions))
return 3;
}

// Copy file times
QString error;
if (!IoUtils::touchFile(target, sourceFile.fileName(), &error)) {
if (!copyFileTimes(targetFile, sourceFile.fileName(), preservePermissions, &error)) {
fprintf(stderr, "%s", qPrintable(error));
return 3;
}

return 0;
}

Expand Down
3 changes: 0 additions & 3 deletions tests/auto/tools/qmake/tst_qmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,6 @@ void tst_qmake::qinstall()
QFile srcfile(src.filePath("main.cpp"));
QVERIFY(srcfile.setPermissions(srcfile.permissions() & ~writeFlags));
QDir dst("zort");
#ifdef Q_OS_WIN
QEXPECT_FAIL("", "QTBUG-77299", Abort);
#endif
QVERIFY(qinstall(src.absolutePath(), dst.absolutePath()));
QCOMPARE(src.entryList(QDir::Files, QDir::Name), dst.entryList(QDir::Files, QDir::Name));
}
Expand Down

0 comments on commit 31e0d17

Please sign in to comment.