Reverted the use of bool in favour of gboolean
[midnight-commander.git] / src / filenot.c
blobc1fcffa4434e75440c0b42abc420385933081a40
1 /*
2 filenot.c: wrapper for routines to notify the
3 tree about the changes made to the directory
4 structure.
6 Author:
7 Janne Kukonlehto
8 Miguel de Icaza
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <config.h>
27 #include <errno.h>
28 #include <string.h>
30 #include <mhl/memory.h>
31 #include <mhl/string.h>
33 #include "global.h"
35 static char *
36 get_absolute_name (const char *file)
38 char dir[MC_MAXPATHLEN];
40 if (file[0] == PATH_SEP)
41 return g_strdup (file);
42 mc_get_current_wd (dir, MC_MAXPATHLEN);
43 return mhl_str_dir_plus_file (dir, file);
46 static int
47 my_mkdir_rec (char *s, mode_t mode)
49 char *p, *q;
50 int result;
52 if (!mc_mkdir (s, mode))
53 return 0;
54 else if (errno != ENOENT)
55 return -1;
57 /* FIXME: should check instead if s is at the root of that filesystem */
58 if (!vfs_file_is_local (s))
59 return -1;
61 if (!strcmp (s, PATH_SEP_STR)) {
62 errno = ENOTDIR;
63 return -1;
66 p = mhl_str_dir_plus_file (s, "..");
67 q = vfs_canon (p);
68 g_free (p);
70 if (!(result = my_mkdir_rec (q, mode)))
71 result = mc_mkdir (s, mode);
73 g_free (q);
74 return result;
77 int
78 my_mkdir (const char *s, mode_t mode)
80 int result;
81 char *my_s;
83 result = mc_mkdir (s, mode);
84 if (result) {
85 char *p = vfs_canon (s);
87 result = my_mkdir_rec (p, mode);
88 g_free (p);
90 if (result == 0) {
91 my_s = get_absolute_name (s);
93 #ifdef FIXME
94 tree_add_entry (tree, my_s);
95 #endif
97 g_free (my_s);
99 return result;
103 my_rmdir (const char *s)
105 int result;
106 char *my_s;
107 #ifdef FIXME
108 WTree *tree = 0;
109 #endif
111 /* FIXME: Should receive a Wtree! */
112 result = mc_rmdir (s);
113 if (result == 0) {
114 my_s = get_absolute_name (s);
116 #ifdef FIXME
117 tree_remove_entry (tree, my_s);
118 #endif
120 g_free (my_s);
122 return result;