[gnome-boxes/gnome-3-8] express: Correctly set timezone configuration
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/gnome-3-8] express: Correctly set timezone configuration
- Date: Mon, 13 May 2013 16:06:29 +0000 (UTC)
commit be868ea2eef3dd6a3006dd5d4a7423a4f8109ef8
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Apr 30 04:40:29 2013 +0300
express: Correctly set timezone configuration
The libosinfo API expects a standard timezone string rather than
abbreviations (e.g 'Europe/Helsinki' rather than 'EET') but glib API we
use can only give us abbreviations. This patch fixes the issue by
fetching the timezone string directly from the system.
This issue had so far not been noticed because currently libosinfo sets
timezone for only Fedora and up until Fedora 19, Fedora has been
silently ignoring invalid timezone string we have been providing it. In
Fedora 19 however, express installation breaks: Installation stops with
an error and user is expected to set a valid timezone.
https://bugzilla.gnome.org/show_bug.cgi?id=699281
src/unattended-installer.vala | 10 +++-----
src/util-app.vala | 43 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 6 deletions(-)
---
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index 0b49cd8..02b3ab1 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -72,7 +72,7 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
private Gtk.Entry password_entry;
private Gtk.Entry key_entry;
- private string timezone;
+ private string? timezone;
private string lang;
private string hostname;
private string kbd;
@@ -121,10 +121,7 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
add_unattended_file (new UnattendedScriptFile (this, script, filename));
}
- var time = TimeVal ();
- var date = new DateTime.from_timeval_local (time);
- timezone = date.get_timezone_abbreviation ();
-
+ timezone = get_timezone ();
lang = get_preferred_language ();
kbd = lang;
product_key_format = get_product_key_format ();
@@ -229,7 +226,8 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
}
if (key_entry != null && key_entry.text != null)
config.set_reg_product_key (key_entry.text);
- config.set_l10n_timezone (timezone);
+ if (timezone != null)
+ config.set_l10n_timezone (timezone);
config.set_l10n_language (lang);
config.set_l10n_keyboard (kbd);
config.set_hostname (hostname);
diff --git a/src/util-app.vala b/src/util-app.vala
index 0dc2d2d..91f6849 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -472,6 +472,49 @@ namespace Boxes {
}
}
+ [DBus (name = "org.freedesktop.timedate1")]
+ public interface Fdo.timedate1 : Object {
+ public abstract string timezone { owned get; set; }
+ }
+
+ public string? get_timezone () {
+ try {
+ return get_timezone_from_systemd ();
+ } catch (GLib.Error e) {
+ // A system without systemd. :( Lets try the hack'ish way.
+ debug ("Failed to get timezone from systemd: %s", e.message);
+ try {
+ return get_timezone_from_linux ();
+ } catch (GLib.Error e) {
+ warning ("Failed to find system timezone: %s", e.message);
+
+ return null;
+ }
+ }
+ }
+
+ public string get_timezone_from_systemd () throws GLib.Error {
+ Fdo.timedate1 timedate = Bus.get_proxy_sync (BusType.SYSTEM,
+ "org.freedesktop.timedate1",
+ "/org/freedesktop/timedate1");
+ if (timedate.timezone == null)
+ throw new Boxes.Error.INVALID ("Failed to get timezone from systemd");
+
+ return timedate.timezone;
+ }
+
+ public string get_timezone_from_linux () throws GLib.Error {
+ var file = File.new_for_path ("/etc/localtime");
+
+ var info = file.query_info (FileAttribute.STANDARD_SYMLINK_TARGET,
FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
+ var target = info.get_symlink_target ();
+ var tokens = target.split ("zoneinfo/");
+ if (tokens == null || tokens.length < 2)
+ throw new Boxes.Error.INVALID ("Timezone file in unexpected location '%s'", target);
+
+ return tokens[1];
+ }
+
namespace UUID {
[CCode (cname = "uuid_generate", cheader_filename = "uuid/uuid.h")]
internal extern static void generate ([CCode (array_length = false)] uchar[] uuid);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]