forked from mooffie/mc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilenot.c
129 lines (102 loc) · 2.56 KB
/
filenot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
filenot.c: wrapper for routines to notify the
tree about the changes made to the directory
structure.
Author:
Janne Kukonlehto
Miguel de Icaza
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file filenot.c
* \brief Source: wrapper for routines to notify the
* tree about the changes made to the directory
* structure.
*/
#include <config.h>
#include <errno.h>
#include <string.h>
#include "global.h"
#include "fs.h"
#include "util.h"
static char *
get_absolute_name (const char *file)
{
char dir[MC_MAXPATHLEN];
if (file[0] == PATH_SEP)
return g_strdup (file);
mc_get_current_wd (dir, MC_MAXPATHLEN);
return concat_dir_and_file (dir, file);
}
static int
my_mkdir_rec (char *s, mode_t mode)
{
char *p, *q;
int result;
if (!mc_mkdir (s, mode))
return 0;
else if (errno != ENOENT)
return -1;
/* FIXME: should check instead if s is at the root of that filesystem */
if (!vfs_file_is_local (s))
return -1;
if (!strcmp (s, PATH_SEP_STR)) {
errno = ENOTDIR;
return -1;
}
p = concat_dir_and_file (s, "..");
q = vfs_canon (p);
g_free (p);
if (!(result = my_mkdir_rec (q, mode)))
result = mc_mkdir (s, mode);
g_free (q);
return result;
}
int
my_mkdir (const char *s, mode_t mode)
{
int result;
char *my_s;
result = mc_mkdir (s, mode);
if (result) {
char *p = vfs_canon (s);
result = my_mkdir_rec (p, mode);
g_free (p);
}
if (result == 0) {
my_s = get_absolute_name (s);
#ifdef FIXME
tree_add_entry (tree, my_s);
#endif
g_free (my_s);
}
return result;
}
int
my_rmdir (const char *s)
{
int result;
char *my_s;
#ifdef FIXME
WTree *tree = 0;
#endif
/* FIXME: Should receive a Wtree! */
result = mc_rmdir (s);
if (result == 0) {
my_s = get_absolute_name (s);
#ifdef FIXME
tree_remove_entry (tree, my_s);
#endif
g_free (my_s);
}
return result;
}