From b40ac4b858958db136c0e39dc074c74429b568e9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 31 Mar 2020 18:16:01 +0200 Subject: Ensure QTzTimeZonePrivate always tries a non-empty IANA ID QTzTimeZonePrivate::init() was coping with empty and then saving the system ID if the ID it looked up was empty. Better to have its caller ensure it's passed the system ID in place of empty. The system ID is always non-empty, as it falls back to "UTC" if it would otherwise have been empty. Change-Id: I5c74e23f01ef578de0dc1f6d558e9c8c7e65ff53 Reviewed-by: Ulf Hermann --- src/corelib/time/qtimezoneprivate_tz.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/corelib/time/qtimezoneprivate_tz.cpp') diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index bf6963a441..1d1b5b05cb 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -639,7 +639,7 @@ QTzTimeZonePrivate::QTzTimeZonePrivate() // Create a named time zone QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) { - init(ianaId); + init(ianaId.isEmpty() ? systemTimeZoneId() : ianaId); } QTzTimeZonePrivate::~QTzTimeZonePrivate() @@ -852,13 +852,16 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::fetchEntry(const QByteArray &ianaId) void QTzTimeZonePrivate::init(const QByteArray &ianaId) { + // System ID defaults to UTC, so is never empty; and our callers default to + // the system ID if what they're given is empty. + Q_ASSERT(!ianaId.isEmpty()); static QTzTimeZoneCache tzCache; const auto &entry = tzCache.fetchEntry(ianaId); if (entry.m_tranTimes.isEmpty() && entry.m_posixRule.isEmpty()) return; // Invalid after all ! cached_data = std::move(entry); - m_id = ianaId.isEmpty() ? systemTimeZoneId() : ianaId; + m_id = ianaId; } QLocale::Country QTzTimeZonePrivate::country() const -- cgit v1.2.3 From b0383cbd388336f698ceeac11a4f50cdff931dd9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 6 Apr 2020 15:01:06 +0200 Subject: Purge two old time-zone lookup fallbacks We used to need to consult /etc/timezone for the zone name back when Debian, up to Jessie, used a copy of the zoneinfo file as /etc/localtime, instead of a symlink. Jessie's end of life is this May, but Thiago reports that its gcc can't build Qt 5.14, so we may as well remove this fall-back. Newer versions of Debian use a symlink. We used to need to consult /etc/sysconfig/clock for this information back when ancient Red Hat distros copied zoneinfo to /etc/localtime instead of symlinking, but Thiago believes that's now ancient history. So, again, remove this old fallback. Change-Id: I73cb40b926186b311dac6f00fe8743d37a9dfce5 Reviewed-by: Thiago Macieira --- src/corelib/time/qtimezoneprivate_tz.cpp | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'src/corelib/time/qtimezoneprivate_tz.cpp') diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index 1d1b5b05cb..ada19f4eb4 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -1153,29 +1153,6 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const } } - // On Debian Etch up to Jessie, /etc/localtime is a copy of the relevant - // zoneinfo file, whose name is recorded in /etc/timezone: - if (ianaId.isEmpty()) { - QFile tzif(QStringLiteral("/etc/timezone")); - if (tzif.open(QIODevice::ReadOnly)) - ianaId = tzif.readAll().trimmed(); - } - - // On some Red Hat distros /etc/localtime is real file with name held in /etc/sysconfig/clock - // in a line like ZONE="Europe/Oslo" or TIMEZONE="Europe/Oslo" - if (ianaId.isEmpty()) { - QFile tzif(QStringLiteral("/etc/sysconfig/clock")); - if (tzif.open(QIODevice::ReadOnly)) { - while (ianaId.isEmpty() && !tzif.atEnd()) { - const QByteArray line(tzif.readLine().trimmed()); - if (line.startsWith("ZONE=")) - ianaId = line.mid(6, line.length() - 7); - else if (line.startsWith("TIMEZONE=")) - ianaId = line.mid(10, line.length() - 11); - } - } - } - // Some systems (e.g. uClibc) have a default value for $TZ in /etc/TZ: if (ianaId.isEmpty()) { QFile zone(QStringLiteral("/etc/TZ")); -- cgit v1.2.3