From 6aded31eb34b2d85a543a6d4676c9ff64dd3b1c1 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Tue, 25 Apr 2023 15:43:10 +0200 Subject: [PATCH] setting_helpers: reduce dub code parts Note: This line: 'TARGET_PREFIX "/share/zoneinfo/" + zone' will be found in other source files too. It could make sense to unify it globally to avoid duplicating code. --- src/system/setting_helpers.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/system/setting_helpers.cpp b/src/system/setting_helpers.cpp index 3210d537a..a4b65a4cf 100644 --- a/src/system/setting_helpers.cpp +++ b/src/system/setting_helpers.cpp @@ -60,7 +60,7 @@ #include #include #include - +#include #include #include @@ -581,6 +581,7 @@ bool CTZChangeNotifier::changeNotify(const neutrino_locale_t, void *Data) bool found = false; std::string name, zone; printf("CTZChangeNotifier::changeNotify: %s\n", (char *) Data); + std::string zoneinfo = TARGET_PREFIX "/share/zoneinfo/" + zone; xmlDocPtr parser = parseXmlFile("/etc/timezone.xml"); if (parser != NULL) @@ -600,8 +601,10 @@ bool CTZChangeNotifier::changeNotify(const neutrino_locale_t, void *Data) const char *zptr = xmlGetAttribute(search, "zone"); if (zptr) zone = zptr; - if (!access(TARGET_PREFIX "/share/zoneinfo/" + zone, R_OK)) + if (!access(zoneinfo.c_str(), R_OK)) found = true; + else + dprintf(DEBUG_NORMAL, "[CTZChangeNotifier] [%s - %d] %s not found\n", __func__, __LINE__, zoneinfo.c_str()); break; } } @@ -612,7 +615,7 @@ bool CTZChangeNotifier::changeNotify(const neutrino_locale_t, void *Data) if (found) { printf("Timezone: %s -> %s\n", name.c_str(), zone.c_str()); - std::string cmd = TARGET_PREFIX "/share/zoneinfo/" + zone; + std::string cmd = zoneinfo; printf("symlink %s to /etc/localtime\n", cmd.c_str()); if (unlink("/etc/localtime")) perror("unlink failed");