Merge branch '4535_tmpdir_name'
[midnight-commander.git] / src / filemanager / filenot.c
blob0ceed42f3d75b4a6489779b4130908dd574f6db4
1 /*
2 Wrapper for routines to notify the
3 tree about the changes made to the directory
4 structure.
6 Copyright (C) 2011-2024
7 Free Software Foundation, Inc.
9 Author:
10 Janne Kukonlehto
11 Miguel de Icaza
12 Slava Zanko <slavazanko@gmail.com>, 2013
14 This file is part of the Midnight Commander.
16 The Midnight Commander is free software: you can redistribute it
17 and/or modify it under the terms of the GNU General Public License as
18 published by the Free Software Foundation, either version 3 of the License,
19 or (at your option) any later version.
21 The Midnight Commander is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 /** \file filenot.c
32 * \brief Source: wrapper for routines to notify the
33 * tree about the changes made to the directory
34 * structure.
37 #include <config.h>
39 #include <errno.h>
40 #include <string.h>
42 #include "lib/global.h"
43 #include "lib/fs.h"
44 #include "lib/util.h"
45 #include "lib/vfs/vfs.h"
47 #include "filenot.h"
49 /*** global variables ****************************************************************************/
51 /*** file scope macro definitions ****************************************************************/
53 /*** file scope type declarations ****************************************************************/
55 /*** forward declarations (file scope functions) *************************************************/
57 /*** file scope variables ************************************************************************/
59 /* --------------------------------------------------------------------------------------------- */
60 /*** file scope functions ************************************************************************/
61 /* --------------------------------------------------------------------------------------------- */
63 static vfs_path_t *
64 get_absolute_name (const vfs_path_t * vpath)
66 if (vpath == NULL)
67 return NULL;
69 if (IS_PATH_SEP (*vfs_path_get_by_index (vpath, 0)->path))
70 return vfs_path_clone (vpath);
72 return vfs_path_append_vpath_new (vfs_get_raw_current_dir (), vpath, NULL);
75 /* --------------------------------------------------------------------------------------------- */
77 static int
78 my_mkdir_rec (const vfs_path_t * vpath, mode_t mode)
80 vfs_path_t *q;
81 int result;
83 if (mc_mkdir (vpath, mode) == 0)
84 return 0;
85 if (errno != ENOENT)
86 return (-1);
88 /* FIXME: should check instead if vpath is at the root of that filesystem */
89 if (!vfs_file_is_local (vpath))
90 return (-1);
92 if (strcmp (vfs_path_as_str (vpath), PATH_SEP_STR) == 0)
94 errno = ENOTDIR;
95 return (-1);
98 q = vfs_path_append_new (vpath, "..", (char *) NULL);
99 result = my_mkdir_rec (q, mode);
100 vfs_path_free (q, TRUE);
102 if (result == 0)
103 result = mc_mkdir (vpath, mode);
105 return result;
108 /* --------------------------------------------------------------------------------------------- */
109 /*** public functions ****************************************************************************/
110 /* --------------------------------------------------------------------------------------------- */
113 my_mkdir (const vfs_path_t * vpath, mode_t mode)
115 int result;
117 result = my_mkdir_rec (vpath, mode);
118 if (result == 0)
120 vfs_path_t *my_s;
122 my_s = get_absolute_name (vpath);
123 vfs_path_free (my_s, TRUE);
125 return result;
128 /* --------------------------------------------------------------------------------------------- */
131 my_rmdir (const char *path)
133 int result;
134 vfs_path_t *vpath;
136 vpath = vfs_path_from_str_flags (path, VPF_NO_CANON);
137 /* FIXME: Should receive a Wtree! */
138 result = mc_rmdir (vpath);
139 if (result == 0)
141 vfs_path_t *my_s;
143 my_s = get_absolute_name (vpath);
144 vfs_path_free (my_s, TRUE);
146 vfs_path_free (vpath, TRUE);
147 return result;
150 /* --------------------------------------------------------------------------------------------- */