Removed vfs_get_class() function
[midnight-commander.git] / src / filemanager / filenot.c
blob97e413be3979a74205f916165cf055c972e67da0
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.
26 /** \file filenot.c
27 * \brief Source: wrapper for routines to notify the
28 * tree about the changes made to the directory
29 * structure.
32 #include <config.h>
34 #include <errno.h>
35 #include <string.h>
37 #include "lib/global.h"
38 #include "lib/fs.h"
39 #include "lib/util.h"
40 #include "lib/vfs/vfs.h"
42 /*** global variables ****************************************************************************/
44 /*** file scope macro definitions ****************************************************************/
46 /*** file scope type declarations ****************************************************************/
48 /*** file scope variables ************************************************************************/
50 /*** file scope functions ************************************************************************/
51 /* --------------------------------------------------------------------------------------------- */
53 static char *
54 get_absolute_name (const char *file)
56 char dir[MC_MAXPATHLEN];
58 if (file[0] == PATH_SEP)
59 return g_strdup (file);
60 mc_get_current_wd (dir, MC_MAXPATHLEN);
61 return concat_dir_and_file (dir, file);
64 /* --------------------------------------------------------------------------------------------- */
66 static int
67 my_mkdir_rec (char *s, mode_t mode)
69 char *p, *q;
70 int result;
72 if (!mc_mkdir (s, mode))
73 return 0;
74 else if (errno != ENOENT)
75 return -1;
77 /* FIXME: should check instead if s is at the root of that filesystem */
79 vfs_path_t *vpath = vfs_path_from_str (s);
80 if (!vfs_file_is_local (vpath))
82 vfs_path_free (vpath);
83 return -1;
85 vfs_path_free (vpath);
88 if (!strcmp (s, PATH_SEP_STR))
90 errno = ENOTDIR;
91 return -1;
94 p = concat_dir_and_file (s, "..");
96 vfs_path_t *vpath = vfs_path_from_str (p);
97 q = vfs_path_to_str (vpath);
98 vfs_path_free (vpath);
100 g_free (p);
102 result = my_mkdir_rec (q, mode);
103 if (result == 0)
104 result = mc_mkdir (s, mode);
106 g_free (q);
107 return result;
110 /* --------------------------------------------------------------------------------------------- */
111 /*** public functions ****************************************************************************/
112 /* --------------------------------------------------------------------------------------------- */
115 my_mkdir (const char *s, mode_t mode)
117 int result;
118 char *my_s;
120 result = mc_mkdir (s, mode);
121 if (result)
123 vfs_path_t *vpath;
124 char *p;
125 vpath = vfs_path_from_str (s);
126 p = vfs_path_to_str (vpath);
128 result = my_mkdir_rec (p, mode);
129 vfs_path_free (vpath);
130 g_free (p);
132 if (result == 0)
134 my_s = get_absolute_name (s);
136 #ifdef FIXME
137 tree_add_entry (tree, my_s);
138 #endif
140 g_free (my_s);
142 return result;
145 /* --------------------------------------------------------------------------------------------- */
148 my_rmdir (const char *s)
150 int result;
151 char *my_s;
152 #ifdef FIXME
153 WTree *tree = 0;
154 #endif
156 /* FIXME: Should receive a Wtree! */
157 result = mc_rmdir (s);
158 if (result == 0)
160 my_s = get_absolute_name (s);
162 #ifdef FIXME
163 tree_remove_entry (tree, my_s);
164 #endif
166 g_free (my_s);
168 return result;
171 /* --------------------------------------------------------------------------------------------- */