diff options
author | Matthew Loper <mloper@src.gnome.org> | 2000-04-07 06:14:36 +0800 |
---|---|---|
committer | Matthew Loper <mloper@src.gnome.org> | 2000-04-07 06:14:36 +0800 |
commit | f991f6a8adb06a992bfe8be0729df56782e3ef20 (patch) | |
tree | 11e85582c31cc9bd26c0f6083f10e3daf9fc5623 /e-util/e-setup.c | |
parent | f3f2afef4c3c60fa1ba472ef93e8e8516e7027bb (diff) | |
download | gsoc2013-evolution-f991f6a8adb06a992bfe8be0729df56782e3ef20.tar.gz gsoc2013-evolution-f991f6a8adb06a992bfe8be0729df56782e3ef20.tar.zst gsoc2013-evolution-f991f6a8adb06a992bfe8be0729df56782e3ef20.zip |
+ (mkdir_if_necessary): New function.
+ (e_setup_base_dir): Use mkdir_if_necessary().
svn path=/trunk/; revision=2315
Diffstat (limited to 'e-util/e-setup.c')
-rw-r--r-- | e-util/e-setup.c | 94 |
1 files changed, 69 insertions, 25 deletions
diff --git a/e-util/e-setup.c b/e-util/e-setup.c index ba9d483ac2..f88ef97526 100644 --- a/e-util/e-setup.c +++ b/e-util/e-setup.c @@ -8,51 +8,95 @@ */ #include <config.h> #include <sys/stat.h> +#include <errno.h> #include <unistd.h> #include <gnome.h> #include "e-setup.h" char *evolution_dir = NULL; char *evolution_folders_dir = NULL; +char *evolution_shortcuts_dir = NULL; char *evolution_private = NULL; char *evolution_public = NULL; +/* Try to ensure the existence of a directory, by checking for it and + * creating it if necessary. It returns FALSE if it doesn't exist and + * can't be created */ +static gboolean +mkdir_if_necessary (char *dirname) +{ + struct stat s; + + g_assert (dirname); + + /* If we can't stat the dirname... */ + if (stat (dirname, &s) == -1) { + + /* ...it may be because there's no such directory */ + if (errno == ENOENT) { + g_print ("Directory %s doesn't exist; creating...", + dirname); + if (mkdir (dirname, S_IRWXU) == -1) { + g_print ("failed! %s\n", g_strerror (errno)); + return FALSE; + } + else /* directory created! */ + g_print ("success!\n"); + } + /* ..or maybe there's some other problem with the directory */ + else { + + g_print ("There's a problem with accessing " + "\"%s\": %s\n", + dirname, g_strerror(errno)); + return FALSE; + } + } + /* There's a file or directory there. */ + else { + /* if it's a file, complain; otherwise, we're all set */ + if (!S_ISDIR (s.st_mode)) { + g_print ("Evolution is trying to create a directory,\n" + "\"%s\". But there appears to be a file in\n" + "the way. Move it away.\n", + dirname); + return FALSE; + } + } + return TRUE; +} + + gboolean e_setup_base_dir (void) { - struct stat s; + gboolean success = FALSE; + /* try to get the evolution home directory from gnome-config; + if we can't, we'll make a new one at ~/evolution */ evolution_dir = gnome_config_get_string("/Evolution/directories/home"); if (!evolution_dir) evolution_dir = g_concat_dir_and_file (g_get_home_dir (), "evolution"); - if (stat (evolution_dir, &s) == -1){ - if (mkdir (evolution_dir, S_IRWXU) == -1){ - return FALSE; - } - } else { - if (!S_ISDIR (s.st_mode)){ - char *msg; + if (!evolution_folders_dir) + evolution_folders_dir = + g_concat_dir_and_file (evolution_dir, "folders"); - g_error ("Finish implementing this"); - - msg = g_strdup_printf ( - _("Evolution detected that the file `%s' is a not a directory.\n" - "\n" - "Evolution can rename the file, delete the file or shutdown and\n" - "let you fix the problem."), - evolution_dir); - return FALSE; - } - } + if (!evolution_shortcuts_dir) + evolution_shortcuts_dir = + g_concat_dir_and_file (evolution_dir, "shortcuts"); + + if (mkdir_if_necessary (evolution_dir) && + mkdir_if_necessary (evolution_folders_dir) && + mkdir_if_necessary (evolution_shortcuts_dir)) { - evolution_folders_dir = g_concat_dir_and_file (evolution_dir, "folders"); - mkdir (evolution_folders_dir, S_IRWXU); - gnome_config_set_string ("/Evolution/directories/home", - evolution_dir); - gnome_config_sync(); + success = TRUE; + gnome_config_set_string ("/Evolution/directories/home", + evolution_dir); + gnome_config_sync(); + } - return TRUE; + return success; } |