*** empty log message ***
[midnight-commander.git] / src / filenot.c
blob548282bdf1230f46bb723131b46510fef1cad56c
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
9 */
11 #include <config.h>
12 #include <string.h>
13 #include <errno.h>
14 #include "global.h"
15 #include "../vfs/vfs.h"
17 static char *get_absolute_name (char *file)
19 char dir [MC_MAXPATHLEN];
21 if (file [0] == PATH_SEP)
22 return g_strdup (file);
23 mc_get_current_wd (dir, MC_MAXPATHLEN);
24 return concat_dir_and_file (dir, file);
27 static int
28 my_mkdir_rec (char *s, mode_t mode)
30 char *p, *q;
31 int result;
33 if (!mc_mkdir (s, mode))
34 return 0;
35 else if (errno != ENOENT)
36 return -1;
38 /* FIXME: should check instead if s is at the root of that filesystem */
39 if (!vfs_file_is_local (s))
40 return -1;
42 if (!strcmp (s, PATH_SEP_STR)) {
43 errno = ENOTDIR;
44 return -1;
47 p = concat_dir_and_file (s, "..");
48 q = vfs_canon (p);
49 g_free (p);
51 if (!(result = my_mkdir_rec (q, mode)))
52 result = mc_mkdir (s, mode);
54 g_free (q);
55 return result;
58 int
59 my_mkdir (char *s, mode_t mode)
61 int result;
63 result = mc_mkdir (s, mode);
64 #ifdef OS2_NT
65 /* .ado: it will be disabled in OS/2 and NT */
66 /* otherwise crash if directory already exists. */
67 return result;
68 #endif
69 if (result) {
70 char *p = vfs_canon (s);
72 result = my_mkdir_rec (p, mode);
73 g_free (p);
75 if (result == 0){
76 s = get_absolute_name (s);
78 #if FIXME
79 tree_add_entry (tree, s);
80 #endif
82 g_free (s);
84 return result;
87 int my_rmdir (char *s)
89 int result;
90 #if FIXME
91 WTree *tree = 0;
92 #endif
94 /* FIXME: Should receive a Wtree! */
95 result = mc_rmdir (s);
96 if (result == 0){
97 s = get_absolute_name (s);
99 #if FIXME
100 tree_remove_entry (tree, s);
101 #endif
103 g_free (s);
105 return result;