summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2018-10-08 12:05:57 +0200
committerAlexander Larsson <alexander.larsson@gmail.com>2018-10-12 10:07:32 +0200
commitae03bb49ac9bdfb3c335c9283048ade1526e71a8 (patch)
treece214dbd08db780eef782401a80a0e2d4fe5619c
parent6ddf772e978a9e0948f1447ded5ad3da91fa5144 (diff)
downloadflatpak-ae03bb49ac9bdfb3c335c9283048ade1526e71a8.tar.gz
utils: Add flatpak_get_timezone()
This extracts the timezone from the symlink in /etc/localtime as specified in e.g. https://www.freedesktop.org/software/systemd/man/localtime.html If this doesn't exist, or is not a symlink, then it uses the old debian /etc/timezone as specified in https://wiki.debian.org/TimeZoneChanges If nothing else works it falls back to UTC. Closes: #2214 Approved by: alexlarsson (cherry picked from commit 6dec2661897bd0fc8b29a53b518427970b5da5f6)
-rw-r--r--common/flatpak-utils-private.h2
-rw-r--r--common/flatpak-utils.c40
2 files changed, 42 insertions, 0 deletions
diff --git a/common/flatpak-utils-private.h b/common/flatpak-utils-private.h
index d2d8132c..8fa70eb0 100644
--- a/common/flatpak-utils-private.h
+++ b/common/flatpak-utils-private.h
@@ -91,6 +91,8 @@ gboolean flatpak_extension_matches_reason (const char *extension_id,
const char * flatpak_get_bwrap (void);
+char *flatpak_get_timezone (void);
+
char **flatpak_subpaths_merge (char **subpaths1,
char **subpaths2);
diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c
index be440c34..9e68eec4 100644
--- a/common/flatpak-utils.c
+++ b/common/flatpak-utils.c
@@ -646,6 +646,46 @@ flatpak_migrate_from_xdg_app (void)
}
}
+char *
+flatpak_get_timezone (void)
+{
+ g_autofree gchar *symlink = NULL;
+ gchar *etc_timezone = NULL;
+ const gchar *tzdir;
+
+ tzdir = getenv ("TZDIR");
+ if (tzdir == NULL)
+ tzdir = "/usr/share/zoneinfo";
+
+ symlink = flatpak_resolve_link ("/etc/localtime", NULL);
+ if (symlink != NULL)
+ {
+ /* Resolve relative path */
+ g_autofree gchar *canonical = flatpak_canonicalize_filename (symlink);
+ char *canonical_suffix;
+
+ /* Strip the prefix and slashes if possible. */
+ if (g_str_has_prefix (canonical, tzdir))
+ {
+ canonical_suffix = canonical + strlen (tzdir);
+ while (*canonical_suffix == '/')
+ canonical_suffix++;
+
+ return g_strdup (canonical_suffix);
+ }
+ }
+
+ if (g_file_get_contents ("/etc/timezeone", &etc_timezone,
+ NULL, NULL))
+ {
+ g_strchomp (etc_timezone);
+ return etc_timezone;
+ }
+
+ /* Final fall-back is UTC */
+ return g_strdup ("UTC");
+ }
+
static gboolean
is_valid_initial_name_character (gint c, gboolean allow_dash)
{