Fix of memory leak in TreeStore::check_name destruction.
[midnight-commander.git] / src / filemanager / filenot.c
blob721ab2152823c3fec0a2f049b4b5818157fcbdf5
1 /*
2 Wrapper for routines to notify the
3 tree about the changes made to the directory
4 structure.
6 Copyright (C) 2011
7 The Free Software Foundation, Inc.
9 Author:
10 Janne Kukonlehto
11 Miguel de Icaza
13 This file is part of the Midnight Commander.
15 The Midnight Commander is free software: you can redistribute it
16 and/or modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation, either version 3 of the License,
18 or (at your option) any later version.
20 The Midnight Commander is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 /** \file filenot.c
31 * \brief Source: wrapper for routines to notify the
32 * tree about the changes made to the directory
33 * structure.
36 #include <config.h>
38 #include <errno.h>
39 #include <string.h>
41 #include "lib/global.h"
42 #include "lib/fs.h"
43 #include "lib/util.h"
44 #include "lib/vfs/vfs.h"
46 #include "filenot.h"
48 /*** global variables ****************************************************************************/
50 /*** file scope macro definitions ****************************************************************/
52 /*** file scope type declarations ****************************************************************/
54 /*** file scope variables ************************************************************************/
56 /*** file scope functions ************************************************************************/
57 /* --------------------------------------------------------------------------------------------- */
59 static vfs_path_t *
60 get_absolute_name (const vfs_path_t * vpath)
62 if (vpath == NULL)
63 return NULL;
65 if (*(vfs_path_get_by_index (vpath, 0)->path) == PATH_SEP)
66 return vfs_path_clone (vpath);
68 return vfs_path_append_vpath_new (vfs_get_raw_current_dir (), vpath);
71 /* --------------------------------------------------------------------------------------------- */
73 static int
74 my_mkdir_rec (char *s, mode_t mode)
76 char *p, *q;
77 int result;
78 vfs_path_t *s_vpath;
80 s_vpath = vfs_path_from_str (s);
81 if (mc_mkdir (s_vpath, mode) == 0)
83 vfs_path_free (s_vpath);
84 return 0;
86 else if (errno != ENOENT)
88 vfs_path_free (s_vpath);
89 return -1;
92 /* FIXME: should check instead if s is at the root of that filesystem */
94 if (!vfs_file_is_local (s_vpath))
96 vfs_path_free (s_vpath);
97 return -1;
101 if (!strcmp (s, PATH_SEP_STR))
103 errno = ENOTDIR;
104 vfs_path_free (s_vpath);
105 return -1;
108 p = mc_build_filename (s, "..", NULL);
110 vfs_path_t *vpath;
112 vpath = vfs_path_from_str (p);
113 q = vfs_path_to_str (vpath);
114 vfs_path_free (vpath);
116 g_free (p);
118 result = my_mkdir_rec (q, mode);
119 if (result == 0)
120 result = mc_mkdir (s_vpath, mode);
122 vfs_path_free (s_vpath);
123 g_free (q);
124 return result;
127 /* --------------------------------------------------------------------------------------------- */
128 /*** public functions ****************************************************************************/
129 /* --------------------------------------------------------------------------------------------- */
132 my_mkdir (const vfs_path_t * s_vpath, mode_t mode)
134 int result;
136 result = mc_mkdir (s_vpath, mode);
138 if (result != 0)
140 char *p;
142 p = vfs_path_to_str (s_vpath);
143 result = my_mkdir_rec (p, mode);
144 g_free (p);
146 if (result == 0)
148 vfs_path_t *my_s;
150 my_s = get_absolute_name (s_vpath);
151 #ifdef FIXME
152 tree_add_entry (tree, my_s);
153 #endif
154 vfs_path_free (my_s);
156 return result;
159 /* --------------------------------------------------------------------------------------------- */
162 my_rmdir (const char *s)
164 int result;
165 vfs_path_t *vpath;
166 #ifdef FIXME
167 WTree *tree = 0;
168 #endif
170 vpath = vfs_path_from_str_flags (s, VPF_NO_CANON);
171 /* FIXME: Should receive a Wtree! */
172 result = mc_rmdir (vpath);
173 if (result == 0)
175 vfs_path_t *my_s;
177 my_s = get_absolute_name (vpath);
178 #ifdef FIXME
179 tree_remove_entry (tree, my_s);
180 #endif
181 vfs_path_free (my_s);
183 vfs_path_free (vpath);
184 return result;
187 /* --------------------------------------------------------------------------------------------- */