[Xfce4-commits] <postler:master> Take care to create config folders if needed

Christian Dywan noreply at xfce.org
Sat Dec 11 20:08:06 CET 2010


Updating branch refs/heads/master
         to 8bb0abcceda7c0ed5275b77419dbe7a126dde9dc (commit)
       from 1ecf6ebd7fc8b76eaa8811f98c2984f23d7e05da (commit)

commit 8bb0abcceda7c0ed5275b77419dbe7a126dde9dc
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Dec 11 14:28:11 2010 +0100

    Take care to create config folders if needed

 postler/postler-accounts.vala |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/postler/postler-accounts.vala b/postler/postler-accounts.vala
index e4a215e..7ec9b47 100644
--- a/postler/postler-accounts.vala
+++ b/postler/postler-accounts.vala
@@ -122,6 +122,7 @@ namespace Postler {
 public class Postler.Accounts : GLib.Object {
     string location;
     string config_path;
+    string account_file;
     string data_path;
     string? certificate_file;
     GLib.KeyFile keyfile;
@@ -138,9 +139,12 @@ public class Postler.Accounts : GLib.Object {
             reload ();
             return;
         }
+
         unowned string config_dir = Environment.get_user_config_dir ();
+        config_path = config_dir + "/" + Config.PACKAGE_NAME + "/";
+        account_file = config_path + "accountrc";
+
         unowned string data_dir = Environment.get_user_data_dir ();
-        config_path = config_dir + "/" + Config.PACKAGE_NAME + "/accountrc";
         data_path = data_dir + "/" + Config.PACKAGE_NAME + "/mail/";
         /* TODO: Monitor accountrc file and emit a signal */
 
@@ -214,10 +218,13 @@ public class Postler.Accounts : GLib.Object {
                 else
                     assert_not_reached ();
             }
-            FileUtils.set_contents (config_path, keyfile.to_data ());
+
+            if (DirUtils.create_with_parents (config_path, 0700) != 0)
+                throw new GLib.FileError.FAILED (_("Config folder couldn't be created."));
+            FileUtils.set_contents (account_file, keyfile.to_data ());
         }
         catch (GLib.Error error) {
-            GLib.critical ("Failed to save \"%s\": %s", config_path, error.message);
+            GLib.critical ("Failed to save \"%s\": %s", account_file, error.message);
         }
     }
 
@@ -225,10 +232,12 @@ public class Postler.Accounts : GLib.Object {
         try {
             string group = info.name ?? info.address;
             keyfile.remove_group (group);
-            FileUtils.set_contents (config_path, keyfile.to_data ());
+            if (DirUtils.create_with_parents (config_path, 0700) != 0)
+                throw new GLib.FileError.FAILED (_("Config folder couldn't be created."));
+            FileUtils.set_contents (account_file, keyfile.to_data ());
         }
         catch (GLib.Error error) {
-            GLib.critical ("Failed to save \"%s\": %s", config_path, error.message);
+            GLib.critical ("Failed to save \"%s\": %s", account_file, error.message);
         }
     }
 
@@ -256,10 +265,10 @@ public class Postler.Accounts : GLib.Object {
 
         keyfile = new GLib.KeyFile ();
         try {
-            keyfile.load_from_file (config_path, 0);
+            keyfile.load_from_file (account_file, 0);
         }
         catch (GLib.Error error) {
-            GLib.debug ("Failed to load \"%s\": %s", config_path, error.message);
+            GLib.debug ("Failed to load \"%s\": %s", account_file, error.message);
         }
 
         foreach (string group in keyfile.get_groups ()) {



More information about the Xfce4-commits mailing list