From 7cd2d2b7516211d233f657edd98903911536b1ff Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 8 Apr 2020 14:26:50 -0300 Subject: tst_QFileInfo: fix running with systems without /etc/passwd Clear Linux containers running as root may have no /etc/passwd. But they'll have /etc/machine-id because systemd creates that. Also test /proc/version (a Linux-specific file) because that isn't writeable even by root. Take the opportunity to check with access() instead of assuming root and only root can write to the file. Change-Id: Ibdc95e9af7bd456a94ecfffd1603e8359604752b Reviewed-by: Volker Hilsheimer --- tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp') diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 09ef0ea44f..1788c04494 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1887,10 +1887,11 @@ void tst_QFileInfo::isWritable() #if defined (Q_OS_QNX) // On QNX /etc is usually on a read-only filesystem QVERIFY(!QFileInfo("/etc/passwd").isWritable()); #elif defined (Q_OS_UNIX) && !defined(Q_OS_VXWORKS) // VxWorks does not have users/groups - if (::getuid() == 0) - QVERIFY(QFileInfo("/etc/passwd").isWritable()); - else - QVERIFY(!QFileInfo("/etc/passwd").isWritable()); + for (const char *attempt : { "/etc/passwd", "/etc/machine-id", "/proc/version" }) { + if (access(attempt, F_OK) == -1) + continue; + QCOMPARE(QFileInfo(attempt).isWritable(), ::access(attempt, W_OK) == 0); + } #endif } -- cgit v1.2.3