[rygel] core: No need to keep path of config file around
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Subject: [rygel] core: No need to keep path of config file around
- Date: Mon, 13 Jul 2009 15:40:57 +0000 (UTC)
commit b39afd66740d2a04caee0dc8e1d3053c7b77e449
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Mon Jul 13 18:35:48 2009 +0300
core: No need to keep path of config file around
Just keep the 'read_only' flag and write to user's config if this
flag is not set in save method.
src/rygel/rygel-user-config.vala | 26 +++++++++++++-------------
1 files changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala
index 8628943..5508261 100644
--- a/src/rygel/rygel-user-config.vala
+++ b/src/rygel/rygel-user-config.vala
@@ -52,7 +52,7 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
private static UserConfig config;
protected KeyFile key_file;
- private string path; // Path to configuration file
+ private bool read_only;
private dynamic DBus.Object dbus_obj;
private dynamic DBus.Object rygel_obj;
@@ -124,24 +124,20 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
}
public UserConfig (bool read_only=true) throws Error {
+ this.read_only = read_only;
this.key_file = new KeyFile ();
var dirs = new string[2];
dirs[0] = Environment.get_user_config_dir ();
- if (read_only) {
- // We only write to user config
- dirs[1] = BuildConfig.SYS_CONFIG_DIR;
- }
+ dirs[1] = BuildConfig.SYS_CONFIG_DIR;
+ string path;
this.key_file.load_from_dirs (CONFIG_FILE,
dirs,
- out this.path,
+ out path,
KeyFileFlags.KEEP_COMMENTS |
KeyFileFlags.KEEP_TRANSLATIONS);
- debug ("Loaded user configuration from file '%s'", this.path);
- if (read_only) {
- this.path = null; // No need to keep the path around
- }
+ debug ("Loaded user configuration from file '%s'", path);
DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION);
@@ -156,16 +152,20 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
}
public void save () {
- return_if_fail (this.path != null);
+ return_if_fail (!this.read_only);
+
+ // Always write to user's config
+ string path = Path.build_filename (Environment.get_user_config_dir (),
+ CONFIG_FILE);
size_t length;
var data = this.key_file.to_data (out length);
try {
- FileUtils.set_contents (this.path, data, (long) length);
+ FileUtils.set_contents (path, data, (long) length);
} catch (FileError err) {
critical ("Failed to save configuration data to file '%s': %s",
- this.path,
+ path,
err.message);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]