manually merged 232_fix_init_chown_advanced
[midnight-commander.git] / src / filenot.c
blob01e0d784ddd85c32bf54b5243a1dcbd8ce89d653
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/string.h>
32 #include "global.h"
34 static char *
35 get_absolute_name (const char *file)
37 char dir[MC_MAXPATHLEN];
39 if (file[0] == PATH_SEP)
40 return g_strdup (file);
41 mc_get_current_wd (dir, MC_MAXPATHLEN);
42 return mhl_str_dir_plus_file (dir, file);
45 static int
46 my_mkdir_rec (char *s, mode_t mode)
48 char *p, *q;
49 int result;
51 if (!mc_mkdir (s, mode))
52 return 0;
53 else if (errno != ENOENT)
54 return -1;
56 /* FIXME: should check instead if s is at the root of that filesystem */
57 if (!vfs_file_is_local (s))
58 return -1;
60 if (!strcmp (s, PATH_SEP_STR)) {
61 errno = ENOTDIR;
62 return -1;
65 p = mhl_str_dir_plus_file (s, "..");
66 q = vfs_canon (p);
67 g_free (p);
69 if (!(result = my_mkdir_rec (q, mode)))
70 result = mc_mkdir (s, mode);
72 g_free (q);
73 return result;
76 int
77 my_mkdir (const char *s, mode_t mode)
79 int result;
80 char *my_s;
82 result = mc_mkdir (s, mode);
83 if (result) {
84 char *p = vfs_canon (s);
86 result = my_mkdir_rec (p, mode);
87 g_free (p);
89 if (result == 0) {
90 my_s = get_absolute_name (s);
92 #ifdef FIXME
93 tree_add_entry (tree, my_s);
94 #endif
96 g_free (my_s);
98 return result;
102 my_rmdir (const char *s)
104 int result;
105 char *my_s;
106 #ifdef FIXME
107 WTree *tree = 0;
108 #endif
110 /* FIXME: Should receive a Wtree! */
111 result = mc_rmdir (s);
112 if (result == 0) {
113 my_s = get_absolute_name (s);
115 #ifdef FIXME
116 tree_remove_entry (tree, my_s);
117 #endif
119 g_free (my_s);
121 return result;