Added macros for Layout and Misc sections of main config file.
[midnight-commander.git] / src / filemanager / filenot.c
blob23fb488e836c7c1a088889c7b090fc1a6c6d713f
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;
76 if (!mc_mkdir (s, mode))
77 return 0;
78 else if (errno != ENOENT)
79 return -1;
81 /* FIXME: should check instead if s is at the root of that filesystem */
83 vfs_path_t *vpath = vfs_path_from_str (s);
84 if (!vfs_file_is_local (vpath))
86 vfs_path_free (vpath);
87 return -1;
89 vfs_path_free (vpath);
92 if (!strcmp (s, PATH_SEP_STR))
94 errno = ENOTDIR;
95 return -1;
98 p = concat_dir_and_file (s, "..");
100 vfs_path_t *vpath = vfs_path_from_str (p);
101 q = vfs_path_to_str (vpath);
102 vfs_path_free (vpath);
104 g_free (p);
106 result = my_mkdir_rec (q, mode);
107 if (result == 0)
108 result = mc_mkdir (s, mode);
110 g_free (q);
111 return result;
114 /* --------------------------------------------------------------------------------------------- */
115 /*** public functions ****************************************************************************/
116 /* --------------------------------------------------------------------------------------------- */
119 my_mkdir (const char *s, mode_t mode)
121 int result;
122 char *my_s;
124 result = mc_mkdir (s, mode);
125 if (result)
127 vfs_path_t *vpath;
128 char *p;
129 vpath = vfs_path_from_str (s);
130 p = vfs_path_to_str (vpath);
132 result = my_mkdir_rec (p, mode);
133 vfs_path_free (vpath);
134 g_free (p);
136 if (result == 0)
138 my_s = get_absolute_name (s);
140 #ifdef FIXME
141 tree_add_entry (tree, my_s);
142 #endif
144 g_free (my_s);
146 return result;
149 /* --------------------------------------------------------------------------------------------- */
152 my_rmdir (const char *s)
154 int result;
155 char *my_s;
156 #ifdef FIXME
157 WTree *tree = 0;
158 #endif
160 /* FIXME: Should receive a Wtree! */
161 result = mc_rmdir (s);
162 if (result == 0)
164 my_s = get_absolute_name (s);
166 #ifdef FIXME
167 tree_remove_entry (tree, my_s);
168 #endif
170 g_free (my_s);
172 return result;
175 /* --------------------------------------------------------------------------------------------- */