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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*
Wrapper for routines to notify the
tree about the changes made to the directory
structure.
Copyright (C) 2011-2022
Free Software Foundation, Inc.
Author:
Janne Kukonlehto
Miguel de Icaza
Slava Zanko <slavazanko@gmail.com>, 2013
This file is part of the Midnight Commander.
The Midnight Commander 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 3 of the License,
or (at your option) any later version.
The Midnight Commander 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, see <http://www.gnu.org/licenses/>.
*/
/** \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 "lib/global.h"
#include "lib/fs.h"
#include "lib/util.h"
#include "lib/vfs/vfs.h"
#include "filenot.h"
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static vfs_path_t *
get_absolute_name (const vfs_path_t * vpath)
{
if (vpath == NULL)
return NULL;
if (IS_PATH_SEP (*vfs_path_get_by_index (vpath, 0)->path))
return vfs_path_clone (vpath);
return vfs_path_append_vpath_new (vfs_get_raw_current_dir (), vpath, NULL);
}
/* --------------------------------------------------------------------------------------------- */
static int
my_mkdir_rec (const vfs_path_t * vpath, mode_t mode)
{
vfs_path_t *q;
int result;
if (mc_mkdir (vpath, mode) == 0)
return 0;
if (errno != ENOENT)
return (-1);
/* FIXME: should check instead if vpath is at the root of that filesystem */
if (!vfs_file_is_local (vpath))
return (-1);
if (strcmp (vfs_path_as_str (vpath), PATH_SEP_STR) == 0)
{
errno = ENOTDIR;
return (-1);
}
q = vfs_path_append_new (vpath, "..", (char *) NULL);
result = my_mkdir_rec (q, mode);
vfs_path_free (q, TRUE);
if (result == 0)
result = mc_mkdir (vpath, mode);
return result;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
int
my_mkdir (const vfs_path_t * vpath, mode_t mode)
{
int result;
result = my_mkdir_rec (vpath, mode);
if (result == 0)
{
vfs_path_t *my_s;
my_s = get_absolute_name (vpath);
vfs_path_free (my_s, TRUE);
}
return result;
}
/* --------------------------------------------------------------------------------------------- */
int
my_rmdir (const char *path)
{
int result;
vfs_path_t *vpath;
vpath = vfs_path_from_str_flags (path, VPF_NO_CANON);
/* FIXME: Should receive a Wtree! */
result = mc_rmdir (vpath);
if (result == 0)
{
vfs_path_t *my_s;
my_s = get_absolute_name (vpath);
vfs_path_free (my_s, TRUE);
}
vfs_path_free (vpath, TRUE);
return result;
}
/* --------------------------------------------------------------------------------------------- */
|