summaryrefslogtreecommitdiff
path: root/pkgtools/pkgclean
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2005-11-17 22:30:09 +0000
committerrillig <rillig@pkgsrc.org>2005-11-17 22:30:09 +0000
commit4abfc1653663d0a9b7bc14d462796a4f4d025f10 (patch)
tree8523159c24864a22173d8e48e08aabc4fcf4998b /pkgtools/pkgclean
parent50e93617005906350f1654b082ce8dd94bb3d93b (diff)
downloadpkgsrc-4abfc1653663d0a9b7bc14d462796a4f4d025f10.tar.gz
Updated pkgclean to 20051116.
- Replaced the C implementation by a shell program, as the latter is more portable. Fixes PR 26970. Ok'ed by maintainer.
Diffstat (limited to 'pkgtools/pkgclean')
-rw-r--r--pkgtools/pkgclean/Makefile17
-rw-r--r--pkgtools/pkgclean/files/pkgclean.17
-rw-r--r--pkgtools/pkgclean/files/pkgclean.c126
-rw-r--r--pkgtools/pkgclean/files/pkgclean.sh79
4 files changed, 91 insertions, 138 deletions
diff --git a/pkgtools/pkgclean/Makefile b/pkgtools/pkgclean/Makefile
index 5cadca895e2..b0f3846e228 100644
--- a/pkgtools/pkgclean/Makefile
+++ b/pkgtools/pkgclean/Makefile
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.7 2005/04/11 21:47:05 tv Exp $
+# $NetBSD: Makefile,v 1.8 2005/11/17 22:30:09 rillig Exp $
-DISTNAME= pkgclean-20050118
+DISTNAME= pkgclean-20051116
CATEGORIES= pkgtools
MASTER_SITES= # empty
DISTFILES= # empty
@@ -10,25 +10,24 @@ COMMENT= Quickly clean up all work directories in pkgsrc
PKG_INSTALLATION_TYPES= overwrite pkgviews
-NO_CONFIGURE= yes
NO_CHECKSUM= yes
+NO_CONFIGURE= yes
+NO_BUILD= yes
INSTALLATION_DIRS= bin man/man1
do-extract:
@${CP} -R ${FILESDIR} ${WRKSRC}
-do-build:
- ${CC} ${CFLAGS} -o ${WRKSRC}/pkgclean ${WRKSRC}/pkgclean.c
-
do-install:
- ${INSTALL_PROGRAM} ${WRKSRC}/pkgclean ${PREFIX}/bin/pkgclean
+ ${INSTALL_SCRIPT} ${WRKSRC}/pkgclean.sh ${PREFIX}/bin/pkgclean
${INSTALL_MAN} ${WRKSRC}/pkgclean.1 ${PREFIX}/man/man1/pkgclean.1
SUBST_CLASSES= path
SUBST_STAGE.path= post-patch
-SUBST_FILES.path= pkgclean.c pkgclean.1
-SUBST_SED.path= -e "s,@PKGSRCDIR@,${PKGSRCDIR},g"
+SUBST_FILES.path= pkgclean.sh pkgclean.1
+SUBST_SED.path+= -e 's,@SH@,${SH},g'
+SUBST_SED.path+= -e 's,@PKGSRCDIR@,${PKGSRCDIR},g'
SUBST_MESSAGE.path= "Adjusting pkgsrc directory."
.include "../../mk/bsd.pkg.mk"
diff --git a/pkgtools/pkgclean/files/pkgclean.1 b/pkgtools/pkgclean/files/pkgclean.1
index 291b7845452..0aa88488231 100644
--- a/pkgtools/pkgclean/files/pkgclean.1
+++ b/pkgtools/pkgclean/files/pkgclean.1
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 16, 2004
+.Dd November 16, 2005
.Dt PKGCLEAN 1
.Sh NAME
.Nm pkgclean
@@ -51,5 +51,6 @@ the environment variable
.Pa PKGSRCDIR .
.Sh SEE ALSO
http://www.pkgsrc.org/
-.Sh AUTHOR
-.An Peter Postma Aq peter@pointless.nl
+.Sh AUTHORS
+.An Peter Postma Aq peter@pointless.nl ,
+.An Roland Illig Aq rillig@NetBSD.org .
diff --git a/pkgtools/pkgclean/files/pkgclean.c b/pkgtools/pkgclean/files/pkgclean.c
deleted file mode 100644
index 2af58555527..00000000000
--- a/pkgtools/pkgclean/files/pkgclean.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 2004 Peter Postma <peter@pointless.nl>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-
-#include <err.h>
-#include <dirent.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#define PKGSRCDIR "@PKGSRCDIR@"
-
-static const char * const skip[] = {
- ".", "..", "CVS", "bootstrap", "doc", "distfiles",
- "licenses", "mk", "packages", NULL
-};
-
-static void pkgclean(const char *, const char *);
-static int checkskip(const struct dirent *);
-
-int
-main(int argc, char *argv[])
-{
- const char *path, *work = "work";
-
- if ((path = getenv("PKGSRCDIR")) == NULL)
- path = PKGSRCDIR;
-
- if (argc > 1)
- work = argv[1];
-
- pkgclean(path, work);
-
- return 0;
-}
-
-static void
-pkgclean(const char *path, const char *work)
-{
- struct dirent **cat, **list;
- int status, ncat, nlist, i, j;
- char tmp[PATH_MAX];
- struct stat sb;
- pid_t pid;
-
- if ((ncat = scandir(path, &cat, checkskip, alphasort)) < 0)
- err(EXIT_FAILURE, "scandir: %s", path);
-
- for (i = 0; i < ncat; i++) {
- if (snprintf(tmp, sizeof(tmp), "%s/%s", path, cat[i]->d_name)
- >= sizeof(tmp)) {
- warnx("filename too long: %s", tmp);
- continue;
- }
- if (stat(tmp, &sb) < 0 || !S_ISDIR(sb.st_mode))
- continue;
- if ((nlist = scandir(tmp, &list, checkskip, alphasort)) < 0) {
- warn("scandir: %s", tmp);
- continue;
- }
- for (j = 0; j < nlist; j++) {
- if (snprintf(tmp, sizeof(tmp), "%s/%s/%s/%s", path,
- cat[i]->d_name, list[j]->d_name, work) >= sizeof(tmp)) {
- warnx("filename too long: %s", tmp);
- continue;
- }
- if (stat(tmp, &sb) < 0 || !S_ISDIR(sb.st_mode))
- continue;
- (void)printf("Deleting %s\n", tmp);
- pid = fork();
- if (pid < 0) {
- warn("fork");
- continue;
- } else if (pid == 0)
- (void)execl("/bin/rm", "rm", "-rf", tmp, NULL);
- if (waitpid(pid, &status, 0) == -1)
- err(EXIT_FAILURE, "waitpid");
- if (WEXITSTATUS(status))
- warn("/bin/rm terminated abnormally");
- free(list[j]);
- }
- free(cat[i]);
- }
- free(list);
- free(cat);
-}
-
-static int
-checkskip(const struct dirent *dp)
-{
- const char * const *p;
-
- for (p = skip; *p != NULL; p++)
- if (strcmp(dp->d_name, *p) == 0)
- return 0;
- return 1;
-}
diff --git a/pkgtools/pkgclean/files/pkgclean.sh b/pkgtools/pkgclean/files/pkgclean.sh
new file mode 100644
index 00000000000..38ba0956982
--- /dev/null
+++ b/pkgtools/pkgclean/files/pkgclean.sh
@@ -0,0 +1,79 @@
+#! @SH@
+# $NetBSD: pkgclean.sh,v 1.1 2005/11/17 22:30:30 rillig Exp $
+#
+
+# Copyright (c) 2005 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Roland Illig <rillig@NetBSD.org>.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by the NetBSD
+# Foundation, Inc. and its contributors.
+# 4. Neither the name of The NetBSD Foundation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+#
+# Command line parsing
+#
+
+pkgsrcdir=${PKGSRCDIR-@PKGSRCDIR@}
+
+case $# in
+0) wrkdir_basename="work";;
+1) wrkdir_basename="$1";;
+esac
+
+#
+# Sanity checks
+#
+
+case $pkgsrcdir in
+/*) ;;
+*) echo "$0: error: PKGSRCDIR must be an absolute path." 1>&2
+ exit 1;;
+esac
+case $wrkdir_basename in
+*/*) echo "$0: error: wrkdir_basename must not contain slashes." 1>&2
+ exit 1;;
+esac
+
+#
+# Clean up the pkgsrc directory
+#
+
+for wrkdir in "${pkgsrcdir}"/*/*/"${wrkdir_basename}"; do
+ echo "===> Cleaning in ${wrkdir}"
+
+ # When WRKOBJDIR is set, ${wrkdir_basename} is just a symlink to
+ # a real directory, so both must be removed properly.
+ if real_wrkdir=`cd "${wrkdir}"/. 2>/dev/null && exec pwd`; then
+ rm -rf "${real_wrkdir}"
+ fi
+
+ rm -rf "${wrkdir}"
+done