diff options
author | Ross Burton <ross@burtonini.com> | 2008-06-11 16:19:39 +0000 |
---|---|---|
committer | Ross Burton <rburton@src.gnome.org> | 2008-06-11 16:19:39 +0000 |
commit | 8ac2afc0d220b6bdbaed79687f205f47f5babde3 (patch) | |
tree | c5014f9ad22b37a7c0e1d1a419b452bed64c6e9c /programs | |
parent | 7c294254e21706b26d955311e067c0e0ac1a87e4 (diff) | |
download | gvfs-8ac2afc0d220b6bdbaed79687f205f47f5babde3.tar.gz |
Add -p to create parents (using g_file_make_directory_with_parents, just
2008-06-11 Ross Burton <ross@burtonini.com>
* programs/gvfs-mkdir.c:
Add -p to create parents (using
g_file_make_directory_with_parents, just landed in glib). Patch
from A Walton (#511367)
svn path=/trunk/; revision=1807
Diffstat (limited to 'programs')
-rw-r--r-- | programs/gvfs-mkdir.c | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/programs/gvfs-mkdir.c b/programs/gvfs-mkdir.c index ac8c2678..483ebd87 100644 --- a/programs/gvfs-mkdir.c +++ b/programs/gvfs-mkdir.c @@ -23,11 +23,14 @@ #include <config.h> #include <glib.h> +#include <glib/gi18n.h> #include <locale.h> #include <gio/gio.h> +static gboolean parent = FALSE; static GOptionEntry entries[] = { + { "parent", 'p', 0, G_OPTION_ARG_NONE, &parent, "create parent directories", NULL }, { NULL } }; @@ -48,21 +51,44 @@ main (int argc, char *argv[]) g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); + + if (error != NULL) + { + g_printerr ("Error parsing commandline options: %s\n", error->message); + g_printerr ("\n"); + g_printerr (_("Try \"%s --help\" for more information."), + g_get_prgname ()); + g_printerr ("\n"); + g_error_free(error); + return 1; + } if (argc > 1) { int i; - for (i = 1; i < argc; i++) { - file = g_file_new_for_commandline_arg (argv[i]); - error = NULL; - if (!g_file_make_directory (file, NULL, &error)) - { - g_print ("Error creating directory: %s\n", error->message); - g_error_free (error); - } - g_object_unref (file); - } + for (i = 1; i < argc; i++) + { + file = g_file_new_for_commandline_arg (argv[i]); + error = NULL; + if (parent) + { + if (!g_file_make_directory_with_parents (file, NULL, &error)) + { + g_print ("Error creating directory: %s\n", error->message); + g_error_free (error); + } + } + else + { + if (!g_file_make_directory (file, NULL, &error)) + { + g_print ("Error creating directory: %s\n", error->message); + g_error_free (error); + } + g_object_unref (file); + } + } } return 0; |