diff --git a/src/mu-cmd.c b/src/mu-cmd.c
index e05235d0..a3ebc3a3 100644
--- a/src/mu-cmd.c
+++ b/src/mu-cmd.c
@@ -471,15 +471,14 @@ cmd_mkdir (MuConfigOptions *opts)
return FALSE; /* shouldn't happen */
if (!opts->params[1]) {
- g_printerr ("usage: mu mkdir
[more dirs]\n");
+ g_printerr (
+ "usage: mu mkdir [-u,--mode=] [more dirs]\n");
return FALSE;
}
i = 1;
while (opts->params[i]) {
- MU_WRITE_LOG ("mu_maildir_mkdir (%s, 0755, FALSE)",
- opts->params[i]);
- if (!mu_maildir_mkmdir (opts->params[i], 0755, FALSE))
+ if (!mu_maildir_mkmdir (opts->params[i], opts->dirmode, FALSE))
return FALSE;
++i;
}
diff --git a/src/mu-config.c b/src/mu-config.c
index b6530010..e9afee88 100644
--- a/src/mu-config.c
+++ b/src/mu-config.c
@@ -26,8 +26,8 @@
#include "mu-config.h"
-GOptionGroup*
-mu_config_options_group_mu (MuConfigOptions *opts)
+static GOptionGroup*
+config_options_group_mu (MuConfigOptions *opts)
{
GOptionGroup *og;
GOptionEntry entries[] = {
@@ -56,8 +56,8 @@ mu_config_options_group_mu (MuConfigOptions *opts)
-GOptionGroup*
-mu_config_options_group_index (MuConfigOptions *opts)
+static GOptionGroup*
+config_options_group_index (MuConfigOptions *opts)
{
GOptionGroup *og;
GOptionEntry entries[] = {
@@ -78,8 +78,8 @@ mu_config_options_group_index (MuConfigOptions *opts)
return og;
}
-GOptionGroup*
-mu_config_options_group_find (MuConfigOptions *opts)
+static GOptionGroup*
+config_options_group_find (MuConfigOptions *opts)
{
GOptionGroup *og;
GOptionEntry entries[] = {
@@ -107,15 +107,25 @@ mu_config_options_group_find (MuConfigOptions *opts)
}
-void
-mu_config_init (MuConfigOptions *opts)
+static GOptionGroup*
+config_options_group_mkdir (MuConfigOptions *opts)
{
- g_return_if_fail (opts);
+ GOptionGroup *og;
+ GOptionEntry entries[] = {
+ {"mode", 'p', 0, G_OPTION_ARG_INT, &opts->dirmode,
+ "set the mode (as in chmod), in octal notation", NULL},
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };
- /* start from zero */
- memset (opts, 0, sizeof(MuConfigOptions));
+ og = g_option_group_new ("mkdir",
+ "options for the 'mkdir' command",
+ "", NULL, NULL);
+ g_option_group_add_entries (og, entries);
+
+ return og;
}
+
static gchar*
guess_muhome (void)
{
@@ -133,11 +143,48 @@ guess_muhome (void)
}
-void
-mu_config_set_defaults (MuConfigOptions *opts)
+static gboolean
+parse_params (MuConfigOptions *config, int *argcp, char ***argvp)
+{
+ GError *error = NULL;
+ GOptionContext *context;
+ gboolean rv;
+
+ context = g_option_context_new ("- maildir utilities");
+
+ g_option_context_set_main_group (context,
+ config_options_group_mu (config));
+ g_option_context_add_group (context,
+ config_options_group_index (config));
+ g_option_context_add_group (context,
+ config_options_group_find (config));
+ g_option_context_add_group (context,
+ config_options_group_mkdir (config));
+
+ rv = g_option_context_parse (context, argcp, argvp, &error);
+ if (!rv) {
+ g_printerr ("error in options: %s\n", error->message);
+ g_error_free (error);
+ } else
+ g_option_context_free (context);
+
+ return rv;
+}
+
+
+gboolean
+mu_config_init (MuConfigOptions *opts, int *argcp, char ***argvp)
{
gchar *old;
- g_return_if_fail (opts);
+
+ g_return_if_fail (opts);
+ memset (opts, 0, sizeof(MuConfigOptions));
+
+ /* set dirmode before, because '0000' is a valid mode */
+ opts->dirmode = 0755;
+
+ if (!parse_params (opts, argcp, argvp))
+ return FALSE;
if (!opts->muhome)
opts->muhome = guess_muhome ();
@@ -153,7 +200,7 @@ mu_config_set_defaults (MuConfigOptions *opts)
else
opts->maildir = mu_util_guess_maildir();
g_free (old);
-
+
/* querying */
/* note, when no fields are specified, we use
@@ -170,8 +217,9 @@ mu_config_set_defaults (MuConfigOptions *opts)
opts->linksdir = mu_util_dir_expand (opts->linksdir);
g_free(old);
}
-}
+ return TRUE;
+}
void
mu_config_uninit (MuConfigOptions *opts)
diff --git a/src/mu-config.h b/src/mu-config.h
index c973c1c9..7ea0f264 100644
--- a/src/mu-config.h
+++ b/src/mu-config.h
@@ -21,6 +21,8 @@
#define __MU_CONFIG_H__
#include
+#include /* for mode_t */
+
#include "mu-msg-fields.h"
G_BEGIN_DECLS
@@ -54,6 +56,9 @@ struct _MuConfigOptions {
gboolean clearlinks; /* clear a linksdir before filling */
gboolean descending; /* sort descending? */
+
+ /* options for mkdir */
+ mode_t dirmode; /* mode for the created maildir */
};
typedef struct _MuConfigOptions MuConfigOptions;
@@ -65,14 +70,8 @@ typedef struct _MuConfigOptions MuConfigOptions;
*
* @param opts options
*/
-void mu_config_init (MuConfigOptions *opts);
+gboolean mu_config_init (MuConfigOptions *opts, int *argcp, char ***argvp);
-/**
- * fill unset config options with defaults
- *
- * @param opts options
- */
-void mu_config_set_defaults (MuConfigOptions *opts);
/**
* free the MuOptionsCOnfig structure; the the muhome and maildir
@@ -82,33 +81,6 @@ void mu_config_set_defaults (MuConfigOptions *opts);
*/
void mu_config_uninit (MuConfigOptions *opts);
-/**
- * get the general options option group
- *
- * @param opts the MuConfigOptions to fill from this option group
- *
- * @return a new option group; *DON'T* unref when added to an optioncontext
- */
-GOptionGroup* mu_config_options_group_mu (MuConfigOptions *opts);
-
-/**
- * get the index-options option group
- *
- * @param opts the MuConfigOptions to fill from this option group
- *
- * @return a new option group; *DON'T* unref when added to an optioncontext
- */
-GOptionGroup* mu_config_options_group_index (MuConfigOptions *opts);
-
-/**
- * get the find-options option group
- *
- * @param opts the MuConfigOptions to fill from this option group
- *
- * @return a new option group; *DON'T* unref when added to an optioncontext
- */
-GOptionGroup* mu_config_options_group_find (MuConfigOptions *opts);
-
G_END_DECLS
diff --git a/src/mu.c b/src/mu.c
index 4c0368f5..aa409671 100644
--- a/src/mu.c
+++ b/src/mu.c
@@ -46,34 +46,6 @@ init_log (MuConfigOptions *opts)
return rv;
}
-static gboolean
-parse_params (MuConfigOptions *config, int *argcp, char ***argvp)
-{
- GError *error = NULL;
- GOptionContext *context;
- gboolean rv;
-
- context = g_option_context_new ("- maildir utilities");
-
- g_option_context_set_main_group (context,
- mu_config_options_group_mu (config));
- g_option_context_add_group (context,
- mu_config_options_group_index (config));
- g_option_context_add_group (context,
- mu_config_options_group_find (config));
-
- rv = g_option_context_parse (context, argcp, argvp, &error);
- if (!rv) {
- g_printerr ("error in options: %s\n", error->message);
- g_error_free (error);
- } else {
- g_option_context_free (context);
- mu_config_set_defaults (config);
- }
-
- return rv;
-}
-
int
main (int argc, char *argv[])
@@ -83,23 +55,17 @@ main (int argc, char *argv[])
g_type_init ();
- mu_config_init (&config);
-
- do {
- rv = FALSE;
+ if (!mu_config_init (&config, &argc, &argv))
+ return 1;
- if (!parse_params (&config, &argc, &argv))
- break;
-
- if (!init_log (&config))
- break;
-
- rv = mu_cmd_execute (&config);
-
- mu_log_uninit();
-
- } while (0);
+ if (!init_log (&config)) {
+ mu_config_uninit (&config);
+ return 1;
+ }
+
+ rv = mu_cmd_execute (&config);
+ mu_log_uninit();
mu_config_uninit (&config);
return rv ? 0 : 1;