Restore support for reading /etc/timezone for system zone name
This restores one of the two mechanisms removed in
commit b0383cbd38,
transformed to fit in with the new cached system-zone determination.
Fixes: QTBUG-87326
Pick-to: 6.1 6.0 5.15
Change-Id: Ic270acb0d958e17dbc74a0ff93a5a1843c939678
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
parent
47abdbea81
commit
824d963700
|
|
@ -1187,8 +1187,11 @@ public:
|
|||
*/
|
||||
const StatIdent local = identify("/etc/localtime");
|
||||
const StatIdent tz = identify("/etc/TZ");
|
||||
if (!m_name.isEmpty() && m_last.isValid() && (m_last == local || m_last == tz))
|
||||
const StatIdent timezone = identify("/etc/timezone");
|
||||
if (!m_name.isEmpty() && m_last.isValid()
|
||||
&& (m_last == local || m_last == tz || m_last == timezone)) {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
m_name = etcLocalTime();
|
||||
if (!m_name.isEmpty()) {
|
||||
|
|
@ -1196,12 +1199,19 @@ public:
|
|||
return m_name;
|
||||
}
|
||||
|
||||
m_name = etcTZ();
|
||||
m_last = m_name.isEmpty() ? StatIdent() : tz;
|
||||
// Some systems (e.g. uClibc) have a default value for $TZ in /etc/TZ:
|
||||
m_name = etcContent(QStringLiteral("/etc/TZ"));
|
||||
if (!m_name.isEmpty()) {
|
||||
m_last = tz;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
// Gentoo still (2020, QTBUG-87326) uses this:
|
||||
m_name = etcContent(QStringLiteral("/etc/timezone"));
|
||||
m_last = m_name.isEmpty() ? StatIdent() : timezone;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
QByteArray m_name;
|
||||
struct StatIdent
|
||||
|
|
@ -1242,10 +1252,8 @@ private:
|
|||
return QByteArray();
|
||||
}
|
||||
|
||||
static QByteArray etcTZ()
|
||||
static QByteArray etcContent(const QString &path)
|
||||
{
|
||||
// Some systems (e.g. uClibc) have a default value for $TZ in /etc/TZ:
|
||||
const QString path = QStringLiteral("/etc/TZ");
|
||||
QFile zone(path);
|
||||
if (zone.open(QIODevice::ReadOnly))
|
||||
return zone.readAll().trimmed();
|
||||
|
|
|
|||
Loading…
Reference in New Issue