From f8b21568ef2e249dbdd6f56d14e1f00aff6e75f7 Mon Sep 17 00:00:00 2001 From: Steven Luo Date: Thu, 17 Dec 2009 04:49:37 -0800 Subject: [PATCH] Try to create CONFIGFILE_DIR if it doesn't exist --- config-ui/browser-switchboard-cp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/config-ui/browser-switchboard-cp.c b/config-ui/browser-switchboard-cp.c index 1ed654b..dad6b68 100644 --- a/config-ui/browser-switchboard-cp.c +++ b/config-ui/browser-switchboard-cp.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -152,9 +153,19 @@ static void save_config(void) { int other_browser_cmd_seen = 0; struct swb_config_line line; - /* Put together the path to the new config file and the tempfile */ + /* If CONFIGFILE_DIR doesn't exist already, try to create it */ if (!(homedir = getenv("HOME"))) homedir = DEFAULT_HOMEDIR; + len = strlen(homedir) + strlen(CONFIGFILE_DIR) + 1; + if (!(newfile = calloc(len, sizeof(char)))) + return; + snprintf(newfile, len, "%s%s", homedir, CONFIGFILE_DIR); + if (access(newfile, F_OK) == -1 && errno == ENOENT) { + mkdir(newfile, 0750); + } + free(newfile); + + /* Put together the path to the new config file and the tempfile */ len = strlen(homedir) + strlen(CONFIGFILE_LOC) + 1; if (!(newfile = calloc(len, sizeof(char)))) return; -- 1.7.9.5