Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[qtbase] Detect system time zone from linked symlinks.
  • Loading branch information
dcaliste committed May 21, 2019
1 parent a002c4e commit 4c5e5b9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/corelib/tools/qtimezoneprivate_tz.cpp
Expand Up @@ -1013,11 +1013,18 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const

// On other distros /etc/localtime is symlink to real file so can extract name from the path
if (ianaId.isEmpty()) {
const QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime"));
if (!path.isEmpty()) {
QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime"));
int index;
int iteration = 0;
// Symlink may point to another symlink etc. before being under zoneinfo/
while (iteration < 5 && !path.isEmpty()
&& (index = path.indexOf(QLatin1String("/zoneinfo/"))) < 0) {
path = QFile::symLinkTarget(path);
iteration += 1;
}
if (!path.isEmpty() && index >= 0) {
// /etc/localtime is a symlink to the current TZ file, so extract from path
int index = path.indexOf(QLatin1String("/zoneinfo/")) + 10;
ianaId = path.mid(index).toUtf8();
ianaId = path.mid(index + 10).toUtf8();
}
}

Expand Down

0 comments on commit 4c5e5b9

Please sign in to comment.