Warning, /libraries/xdg-portal-test-kde/flatpak-build/patch/qtbase-revert-qstandardpaths-dont-change-permissions-on-xdg-runtime-dir.patch is written in an unsupported language. File is not indexed.

0001 From 689f77c63a4e9480ce2c8576fdbeb11ab30d206c Mon Sep 17 00:00:00 2001
0002 From: Jan Grulich <jgrulich@redhat.com>
0003 Date: Thu, 15 Apr 2021 09:09:10 +0200
0004 Subject: Revert "QStandardPaths: Don't change permissions of XDG_RUNTIME_DIR"
0005 
0006 This reverts commit 0fbb484d4aeb4eff50eb4aa312ab8ff41ce4e082.
0007 
0008 diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
0009 index 4ebeefcedb..2e779bef66 100644
0010 --- a/src/corelib/io/qstandardpaths_unix.cpp
0011 +++ b/src/corelib/io/qstandardpaths_unix.cpp
0012 @@ -94,30 +94,6 @@ static QLatin1String xdg_key_name(QStandardPaths::StandardLocation type)
0013  }
0014  #endif
0015  
0016 -static QByteArray unixPermissionsText(QFile::Permissions permissions)
0017 -{
0018 -    mode_t perms = 0;
0019 -    if (permissions & QFile::ReadOwner)
0020 -        perms |= S_IRUSR;
0021 -    if (permissions & QFile::WriteOwner)
0022 -        perms |= S_IWUSR;
0023 -    if (permissions & QFile::ExeOwner)
0024 -        perms |= S_IXUSR;
0025 -    if (permissions & QFile::ReadGroup)
0026 -        perms |= S_IRGRP;
0027 -    if (permissions & QFile::WriteGroup)
0028 -        perms |= S_IWGRP;
0029 -    if (permissions & QFile::ExeGroup)
0030 -        perms |= S_IXGRP;
0031 -    if (permissions & QFile::ReadOther)
0032 -        perms |= S_IROTH;
0033 -    if (permissions & QFile::WriteOther)
0034 -        perms |= S_IWOTH;
0035 -    if (permissions & QFile::ExeOther)
0036 -        perms |= S_IXOTH;
0037 -    return '0' + QByteArray::number(perms, 8);
0038 -}
0039 -
0040  static bool checkXdgRuntimeDir(const QString &xdgRuntimeDir)
0041  {
0042      auto describeMetaData = [](const QFileSystemMetaData &metaData) -> QByteArray {
0043 @@ -137,7 +113,27 @@ static bool checkXdgRuntimeDir(const QString &xdgRuntimeDir)
0044          else
0045              description += "a block device";
0046  
0047 -        description += " permissions " + unixPermissionsText(metaData.permissions());
0048 +        // convert QFileSystemMetaData permissions back to Unix
0049 +        mode_t perms = 0;
0050 +        if (metaData.permissions() & QFile::ReadOwner)
0051 +            perms |= S_IRUSR;
0052 +        if (metaData.permissions() & QFile::WriteOwner)
0053 +            perms |= S_IWUSR;
0054 +        if (metaData.permissions() & QFile::ExeOwner)
0055 +            perms |= S_IXUSR;
0056 +        if (metaData.permissions() & QFile::ReadGroup)
0057 +            perms |= S_IRGRP;
0058 +        if (metaData.permissions() & QFile::WriteGroup)
0059 +            perms |= S_IWGRP;
0060 +        if (metaData.permissions() & QFile::ExeGroup)
0061 +            perms |= S_IXGRP;
0062 +        if (metaData.permissions() & QFile::ReadOther)
0063 +            perms |= S_IROTH;
0064 +        if (metaData.permissions() & QFile::WriteOther)
0065 +            perms |= S_IWOTH;
0066 +        if (metaData.permissions() & QFile::ExeOther)
0067 +            perms |= S_IXOTH;
0068 +        description += " permissions 0" + QByteArray::number(perms, 8);
0069  
0070          return description
0071                  + " owned by UID " + QByteArray::number(metaData.userId())
0072 @@ -190,11 +186,14 @@ static bool checkXdgRuntimeDir(const QString &xdgRuntimeDir)
0073  
0074      // "and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700."
0075      if (metaData.permissions() != wantedPerms) {
0076 -        qWarning("QStandardPaths: wrong permissions on runtime directory %ls, %s instead of %s",
0077 -                 qUtf16Printable(xdgRuntimeDir),
0078 -                 unixPermissionsText(metaData.permissions()).constData(),
0079 -                 unixPermissionsText(wantedPerms).constData());
0080 -        return false;
0081 +        // attempt to correct:
0082 +        QSystemError error;
0083 +        if (!QFileSystemEngine::setPermissions(entry, wantedPerms, error)) {
0084 +            qErrnoWarning("QStandardPaths: could not set correct permissions on runtime directory "
0085 +                          "'%ls', which is %s", qUtf16Printable(xdgRuntimeDir),
0086 +                          describeMetaData(metaData).constData());
0087 +            return false;
0088 +        }
0089      }
0090  
0091      return true;
0092 diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
0093 index a0aefac268..afbd64c405 100644
0094 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
0095 +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
0096 @@ -532,12 +532,7 @@ void tst_qstandardpaths::testCustomRuntimeDirectory_data()
0097          d.mkdir("runtime");
0098          QFile::setPermissions(p, QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner |
0099                                   QFile::ExeGroup | QFile::ExeOther);
0100 -        updateRuntimeDir(p);
0101 -        QTest::ignoreMessage(QtWarningMsg,
0102 -                             QString("QStandardPaths: wrong permissions on runtime directory %1, "
0103 -                                     "0711 instead of 0700")
0104 -                             .arg(p).toLatin1());
0105 -        return fallbackXdgRuntimeDir();
0106 +        return updateRuntimeDir(p);
0107      });
0108  
0109      addRow("environment:wrong-owner", [](QDir &) {
0110 @@ -602,7 +597,6 @@ void tst_qstandardpaths::testCustomRuntimeDirectory_data()
0111          clearRuntimeDir();
0112          QString p = fallbackXdgRuntimeDir();
0113          d.mkdir(p);         // probably has wrong permissions
0114 -        QFile::setPermissions(p, QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
0115          return p;
0116      });
0117