Changed interface of following functions to handle vfs_path_t object as parameter:
[midnight-commander.git] / src / filemanager / filenot.c
blob69422a6b2fe965ac8f559b4a87e1139361f6b52a
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 /*** global variables ****************************************************************************/
48 /*** file scope macro definitions ****************************************************************/
50 /*** file scope type declarations ****************************************************************/
52 /*** file scope variables ************************************************************************/
54 /*** file scope functions ************************************************************************/
55 /* --------------------------------------------------------------------------------------------- */
57 static char *
58 get_absolute_name (const char *file)
60 char dir[MC_MAXPATHLEN];
62 if (file[0] == PATH_SEP)
63 return g_strdup (file);
64 mc_get_current_wd (dir, MC_MAXPATHLEN);
65 return concat_dir_and_file (dir, file);
68 /* --------------------------------------------------------------------------------------------- */
70 static int
71 my_mkdir_rec (char *s, mode_t mode)
73 char *p, *q;
74 int result;
75 vfs_path_t *s_vpath;
77 s_vpath = vfs_path_from_str (s);
78 if (mc_mkdir (s_vpath, mode) == 0)
80 vfs_path_free (s_vpath);
81 return 0;
83 else if (errno != ENOENT)
85 vfs_path_free (s_vpath);
86 return -1;
89 /* FIXME: should check instead if s is at the root of that filesystem */
91 if (!vfs_file_is_local (s_vpath))
93 vfs_path_free (s_vpath);
94 return -1;
98 if (!strcmp (s, PATH_SEP_STR))
100 errno = ENOTDIR;
101 vfs_path_free (s_vpath);
102 return -1;
105 p = concat_dir_and_file (s, "..");
107 vfs_path_t *vpath;
109 vpath = vfs_path_from_str (p);
110 q = vfs_path_to_str (vpath);
111 vfs_path_free (vpath);
113 g_free (p);
115 result = my_mkdir_rec (q, mode);
116 if (result == 0)
117 result = mc_mkdir (s_vpath, mode);
119 vfs_path_free (s_vpath);
120 g_free (q);
121 return result;
124 /* --------------------------------------------------------------------------------------------- */
125 /*** public functions ****************************************************************************/
126 /* --------------------------------------------------------------------------------------------- */
129 my_mkdir (const char *s, mode_t mode)
131 int result;
132 char *my_s;
133 vfs_path_t *s_vpath;
135 s_vpath = vfs_path_from_str (s);
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 my_s = get_absolute_name (s);
150 #ifdef FIXME
151 tree_add_entry (tree, my_s);
152 #endif
154 g_free (my_s);
156 vfs_path_free (s_vpath);
157 return result;
160 /* --------------------------------------------------------------------------------------------- */
163 my_rmdir (const char *s)
165 int result;
166 char *my_s;
167 vfs_path_t *vpath;
168 #ifdef FIXME
169 WTree *tree = 0;
170 #endif
172 vpath = vfs_path_from_str (s);
173 /* FIXME: Should receive a Wtree! */
174 result = mc_rmdir (vpath);
175 if (result == 0)
177 my_s = get_absolute_name (s);
179 #ifdef FIXME
180 tree_remove_entry (tree, my_s);
181 #endif
183 g_free (my_s);
185 vfs_path_free (vpath);
186 return result;
189 /* --------------------------------------------------------------------------------------------- */