4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
38 #include "pkglocale.h"
44 char path
[PATH_MAX
+13];
49 * For some reason, a simple "rm -rf" will remove the contents
50 * of the directory, but will fail to remove the directory itself
51 * with "No such file or directory" when running the pkg commands
52 * under a virtual root via the "chroot" command. This has been
53 * seen so far only with the `pkgremove' command, and when the
54 * the directory is NFS mounted from a 4.x server. This should
55 * probably be revisited at a later time, but for now we'll just
56 * remove the directory contents first, then the directory.
59 /* do not allow removal of all root files via blank path */
61 if ((a_path
== NULL
) || (*a_path
== '\0')) {
62 (void) fprintf(stderr
,
63 pkg_gt("warning: rrmdir(path==NULL): nothing deleted\n"));
68 * first generate path with slash-star at the end and attempt to remove
69 * all files first. If successful then remove with just the path only.
72 (void) snprintf(path
, sizeof (path
), "%s/", a_path
);
73 i
= e_ExecCmdList(&status
, (char **)NULL
, (char *)NULL
,
74 "/bin/rm", "rm", "-rf", path
, (char *)NULL
);
76 if (access(a_path
, F_OK
) == 0) {
77 i
= e_ExecCmdList(&status
, (char **)NULL
, (char *)NULL
,
78 "/bin/rmdir", "rmdir", a_path
, (char *)NULL
);
81 /* return 0 if last command successful, else return 1 */
82 return ((i
== 0 && status
== 0) ? 0 : 1);