Merge branch '44_more_functionally_u7z'
[pantumic.git] / src / filenot.c
blob374834d18c42b07a1af831749841d83ffb985bae
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 "global.h"
38 #include "fs.h"
39 #include "util.h"
41 static char *
42 get_absolute_name (const char *file)
44 char dir[MC_MAXPATHLEN];
46 if (file[0] == PATH_SEP)
47 return g_strdup (file);
48 mc_get_current_wd (dir, MC_MAXPATHLEN);
49 return concat_dir_and_file (dir, file);
52 static int
53 my_mkdir_rec (char *s, mode_t mode)
55 char *p, *q;
56 int result;
58 if (!mc_mkdir (s, mode))
59 return 0;
60 else if (errno != ENOENT)
61 return -1;
63 /* FIXME: should check instead if s is at the root of that filesystem */
64 if (!vfs_file_is_local (s))
65 return -1;
67 if (!strcmp (s, PATH_SEP_STR)) {
68 errno = ENOTDIR;
69 return -1;
72 p = concat_dir_and_file (s, "..");
73 q = vfs_canon (p);
74 g_free (p);
76 if (!(result = my_mkdir_rec (q, mode)))
77 result = mc_mkdir (s, mode);
79 g_free (q);
80 return result;
83 int
84 my_mkdir (const char *s, mode_t mode)
86 int result;
87 char *my_s;
89 result = mc_mkdir (s, mode);
90 if (result) {
91 char *p = vfs_canon (s);
93 result = my_mkdir_rec (p, mode);
94 g_free (p);
96 if (result == 0) {
97 my_s = get_absolute_name (s);
99 #ifdef FIXME
100 tree_add_entry (tree, my_s);
101 #endif
103 g_free (my_s);
105 return result;
109 my_rmdir (const char *s)
111 int result;
112 char *my_s;
113 #ifdef FIXME
114 WTree *tree = 0;
115 #endif
117 /* FIXME: Should receive a Wtree! */
118 result = mc_rmdir (s);
119 if (result == 0) {
120 my_s = get_absolute_name (s);
122 #ifdef FIXME
123 tree_remove_entry (tree, my_s);
124 #endif
126 g_free (my_s);
128 return result;