VirtualBox

source: kBuild/trunk/src/kmk/kmkbuiltin/rmdir.c@ 2912

最後變更 在這個檔案從2912是 2912,由 bird 提交於 9 年 前

rewrote kmk_redirect to skip the separate process. Added chache invalidation after directory deletion for addressing kmk rebuild and fetching.

  • 屬性 svn:eol-style 設為 native
檔案大小: 5.6 KB
 
1/*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#if 0
31#ifndef lint
32static char const copyright[] =
33"@(#) Copyright (c) 1992, 1993, 1994\n\
34 The Regents of the University of California. All rights reserved.\n";
35#endif /* not lint */
36
37#ifndef lint
38static char sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94";
39#endif /* not lint */
40#endif
41#if 0
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: src/bin/rmdir/rmdir.c,v 1.20 2005/01/26 06:51:28 ssouhlal Exp $");
44#endif
45
46#include "config.h"
47#include "err.h"
48#include <stdio.h>
49#include <stdlib.h>
50#include <string.h>
51#include <errno.h>
52#include <unistd.h>
53#ifdef HAVE_ALLOCA_H
54# include <alloca.h>
55#endif
56#include "getopt.h"
57#include "kmkbuiltin.h"
58
59#ifdef _MSC_VER
60# include "mscfakes.h"
61#endif
62#if defined(KMK) && defined(KBUILD_OS_WINDOWS)
63extern int dir_cache_deleted_directory(const char *pszDir);
64#endif
65
66static int rm_path(char *);
67static int usage(FILE *);
68
69static int pflag;
70static int vflag;
71static int ignore_fail_on_non_empty;
72static int ignore_fail_on_not_exist;
73
74static struct option long_options[] =
75{
76 { "help", no_argument, 0, 262 },
77 { "ignore-fail-on-non-empty", no_argument, 0, 260 },
78 { "ignore-fail-on-not-exist", no_argument, 0, 261 },
79 { "parents", no_argument, 0, 'p' },
80 { "verbose", no_argument, 0, 'v' },
81 { "version", no_argument, 0, 263 },
82 { 0, 0, 0, 0 },
83};
84
85
86int
87kmk_builtin_rmdir(int argc, char *argv[], char **envp)
88{
89 int ch, errors;
90
91 /* reinitialize globals */
92 ignore_fail_on_not_exist = ignore_fail_on_non_empty = vflag = pflag = 0;
93
94 /* kmk: reset getopt and set progname */
95 g_progname = argv[0];
96 opterr = 1;
97 optarg = NULL;
98 optopt = 0;
99 optind = 0; /* init */
100 while ((ch = getopt_long(argc, argv, "pv", long_options, NULL)) != -1)
101 switch(ch) {
102 case 'p':
103 pflag = 1;
104 break;
105 case 'v':
106 vflag = 1;
107 break;
108 case 260:
109 ignore_fail_on_non_empty = 1;
110 break;
111 case 261:
112 ignore_fail_on_not_exist = 1;
113 break;
114 case 262:
115 usage(stdout);
116 return 0;
117 case 263:
118 return kbuild_version(argv[0]);
119 case '?':
120 default:
121 return usage(stderr);
122 }
123 argc -= optind;
124 argv += optind;
125
126 if (argc == 0)
127 return /*usage(stderr)*/0;
128
129 for (errors = 0; *argv; argv++) {
130 if (rmdir(*argv) < 0) {
131 if ( (!ignore_fail_on_non_empty || (errno != ENOTEMPTY && errno != EPERM && errno != EACCES && errno != EINVAL && errno != EEXIST))
132 && (!ignore_fail_on_not_exist || errno != ENOENT)) {
133 warn("rmdir: %s", *argv);
134 errors = 1;
135 continue;
136 }
137 if (!ignore_fail_on_not_exist || errno != ENOENT)
138 continue;
139 /* (only ignored doesn't exist errors fall thru) */
140 } else {
141#if defined(KMK) && defined(KBUILD_OS_WINDOWS)
142 dir_cache_deleted_directory(*argv);
143#endif
144 if (vflag) {
145 printf("%s\n", *argv);
146 }
147 }
148 if (pflag)
149 errors |= rm_path(*argv);
150 }
151
152 return errors;
153}
154
155static int
156rm_path(char *path)
157{
158 char *p;
159 const size_t len = strlen(path);
160 p = alloca(len + 1);
161 path = memcpy(p, path, len + 1);
162
163#if defined(_MSC_VER) || defined(__EMX__)
164 p = strchr(path, '\\');
165 while (p) {
166 *p++ = '/';
167 p = strchr(p, '\\');
168 }
169#endif
170
171 p = path + len;
172 while (--p > path && *p == '/')
173 ;
174 *++p = '\0';
175 while ((p = strrchr(path, '/')) != NULL) {
176 /* Delete trailing slashes. */
177 while (--p >= path && *p == '/')
178 ;
179 *++p = '\0';
180 if (p == path)
181 break;
182#if defined(_MSC_VER) || defined(__EMX__)
183 if (p[-1] == ':' && p - 2 == path)
184 break;
185#endif
186
187 if (rmdir(path) < 0) {
188 if ( ignore_fail_on_non_empty
189 && ( errno == ENOTEMPTY || errno == EPERM || errno == EACCES || errno == EINVAL || errno == EEXIST))
190 break;
191 if (!ignore_fail_on_not_exist || errno != ENOENT) {
192 warn("rmdir: %s", path);
193 return (1);
194 }
195 }
196#if defined(KMK) && defined(KBUILD_OS_WINDOWS)
197 else {
198 dir_cache_deleted_directory(path);
199 }
200#endif
201 if (vflag)
202 printf("%s\n", path);
203 }
204
205 return (0);
206}
207
208static int
209usage(FILE *pf)
210{
211 (void)fprintf(pf, "usage: %s [-pv --ignore-fail-on-non-empty --ignore-fail-on-not-exist] directory ...\n"
212 " or: %s --help\n"
213 " or: %s --version\n",
214 g_progname, g_progname, g_progname);
215 return 1;
216}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette