Real home dir (Flatpak remaps QDir::homePath to the sandbox).
| 8 | |
| 9 | // Real home dir (Flatpak remaps QDir::homePath to the sandbox). |
| 10 | inline QString realHomePath() |
| 11 | { |
| 12 | if (QFile::exists("/.flatpak-info")) { |
| 13 | // Try HOST_HOME environment variable first |
| 14 | const char* hostHome = std::getenv("HOST_HOME"); |
| 15 | if (hostHome && hostHome[0]) |
| 16 | return QString::fromUtf8(hostHome); |
| 17 | |
| 18 | // Parse real home from /etc/passwd |
| 19 | QFile passwd("/etc/passwd"); |
| 20 | if (passwd.open(QIODevice::ReadOnly | QIODevice::Text)) { |
| 21 | uid_t uid = getuid(); |
| 22 | while (!passwd.atEnd()) { |
| 23 | QString line = passwd.readLine(); |
| 24 | QStringList fields = line.split(':'); |
| 25 | if (fields.size() >= 6 && fields[2].toULongLong() == static_cast<qulonglong>(uid)) |
| 26 | return fields[5]; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // Last resort: strip the .var/app/<app-id> suffix |
| 31 | QString sandboxHome = QDir::homePath(); |
| 32 | int varAppIdx = sandboxHome.indexOf("/.var/app/"); |
| 33 | if (varAppIdx > 0) |
| 34 | return sandboxHome.left(varAppIdx); |
| 35 | } |
| 36 | return QDir::homePath(); |
| 37 | } |
| 38 | |
| 39 | inline bool inFlatpak() |
| 40 | { |
no test coverage detected