1 /* gnomevfs-mkdir.c - Test for mkdir() for gnome-vfs
3 Copyright (C) 2003, Red Hat
5 The Gnome Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The Gnome Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the Gnome Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
20 Author: Bastien Nocera <hadess@hadess.net>
23 #include <libgnomevfs/gnome-vfs.h>
28 make_directory_with_parents_for_uri (GnomeVFSURI * uri,
31 GnomeVFSResult result;
32 GnomeVFSURI *parent, *work_uri;
35 result = gnome_vfs_make_directory_for_uri (uri, perm);
36 if (result == GNOME_VFS_OK || result != GNOME_VFS_ERROR_NOT_FOUND)
41 while (result == GNOME_VFS_ERROR_NOT_FOUND) {
42 parent = gnome_vfs_uri_get_parent (work_uri);
43 result = gnome_vfs_make_directory_for_uri (parent, perm);
45 if (result == GNOME_VFS_ERROR_NOT_FOUND)
46 list = g_list_prepend (list, parent);
50 if (result != GNOME_VFS_OK) {
52 while (list != NULL) {
53 gnome_vfs_uri_unref ((GnomeVFSURI *) list->data);
54 list = g_list_remove (list, list->data);
58 while (result == GNOME_VFS_OK && list != NULL) {
59 result = gnome_vfs_make_directory_for_uri
60 ((GnomeVFSURI *) list->data, perm);
62 gnome_vfs_uri_unref ((GnomeVFSURI *) list->data);
63 list = g_list_remove (list, list->data);
66 result = gnome_vfs_make_directory_for_uri (uri, perm);
71 make_directory_with_parents (const gchar * text_uri, guint perm)
74 GnomeVFSResult result;
76 uri = gnome_vfs_uri_new (text_uri);
77 result = make_directory_with_parents_for_uri (uri, perm);
78 gnome_vfs_uri_unref (uri);
84 main (int argc, char *argv[])
87 GnomeVFSResult result;
88 gboolean with_parents;
93 if (strcmp (argv[1], "-p") == 0) {
101 fprintf (stderr, "Usage: %s [-p] <dir>\n", argv[0]);
102 fprintf (stderr, " -p: Create parents of the directory if needed\n");
107 result = make_directory_with_parents (argv[1],
108 GNOME_VFS_PERM_USER_ALL
109 | GNOME_VFS_PERM_GROUP_ALL
110 | GNOME_VFS_PERM_OTHER_READ);
112 result = gnome_vfs_make_directory (argv[1],
113 GNOME_VFS_PERM_USER_ALL
114 | GNOME_VFS_PERM_GROUP_ALL
115 | GNOME_VFS_PERM_OTHER_READ);
118 if (result != GNOME_VFS_OK) {
119 g_print ("Error making directory %s\nReason: %s\n",
121 gnome_vfs_result_to_string (result));
125 gnome_vfs_shutdown ();