From owner-svn-src-all@FreeBSD.ORG Thu Dec 25 16:59:35 2008 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 972AD106564A; Thu, 25 Dec 2008 16:59:35 +0000 (UTC) (envelope-from flz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 86BDC8FC14; Thu, 25 Dec 2008 16:59:35 +0000 (UTC) (envelope-from flz@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mBPGxZTH018611; Thu, 25 Dec 2008 16:59:35 GMT (envelope-from flz@svn.freebsd.org) Received: (from flz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mBPGxZog018609; Thu, 25 Dec 2008 16:59:35 GMT (envelope-from flz@svn.freebsd.org) Message-Id: <200812251659.mBPGxZog018609@svn.freebsd.org> From: Florent Thoumie Date: Thu, 25 Dec 2008 16:59:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r186496 - head/usr.sbin/pkg_install/lib X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Dec 2008 16:59:35 -0000 Author: flz Date: Thu Dec 25 16:59:35 2008 New Revision: 186496 URL: http://svn.freebsd.org/changeset/base/186496 Log: Follow symlinks when deleting directories. Bump PKG_INSTALL_VER to 20081225 (Merry Christmas \o/). PR: bin/54446 Submitted by: Andrea Barberio MFC after: 1 month Modified: head/usr.sbin/pkg_install/lib/lib.h head/usr.sbin/pkg_install/lib/plist.c Modified: head/usr.sbin/pkg_install/lib/lib.h ============================================================================== --- head/usr.sbin/pkg_install/lib/lib.h Thu Dec 25 16:44:01 2008 (r186495) +++ head/usr.sbin/pkg_install/lib/lib.h Thu Dec 25 16:59:35 2008 (r186496) @@ -105,7 +105,7 @@ * Version of the package tools - increase only when some * functionality used by bsd.port.mk is changed, added or removed */ -#define PKG_INSTALL_VERSION 20080708 +#define PKG_INSTALL_VERSION 20081225 #define PKG_WRAPCONF_FNAME "/var/db/pkg_install.conf" #define main(argc, argv) real_main(argc, argv) Modified: head/usr.sbin/pkg_install/lib/plist.c ============================================================================== --- head/usr.sbin/pkg_install/lib/plist.c Thu Dec 25 16:44:01 2008 (r186495) +++ head/usr.sbin/pkg_install/lib/plist.c Thu Dec 25 16:59:35 2008 (r186496) @@ -544,45 +544,92 @@ delete_package(Boolean ign_err, Boolean int delete_hierarchy(const char *dir, Boolean ign_err, Boolean nukedirs) { - char *cp1, *cp2; + char *cp1, *cp2, *realdir; - cp1 = cp2 = strdup(dir); - if (!fexists(dir)) { + realdir = malloc(FILENAME_MAX); + if (realdir == NULL) { + warnx("Couldn't allocate enough memory\n"); + return (ign_err ? SUCCESS : FAIL); + } + + if (issymlink(dir) && readlink(dir, realdir, FILENAME_MAX-1) == -1) + return (ign_err ? SUCCESS : FAIL); + + strlcpy(realdir, dir, FILENAME_MAX); + + cp1 = cp2 = strdup(realdir); + if (cp1 == NULL) { + warnx("Couldn't allocate enough memory\n"); + return (ign_err ? SUCCESS : FAIL); + } + + if (!fexists(realdir)) { if (!ign_err) warnx("%s '%s' doesn't exist", - isdir(dir) ? "directory" : "file", dir); - return !ign_err; + isdir(realdir) ? "directory" : "file", realdir); + free(cp1); + free(realdir); + return (ign_err ? SUCCESS : FAIL); } else if (nukedirs) { - if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir)) - return 1; + if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), realdir)) { + free(cp1); + free(realdir); + return (ign_err ? SUCCESS : FAIL); + } } - else if (isdir(dir) && !issymlink(dir)) { - if (RMDIR(dir) && !ign_err) - return 1; + else if (isdir(realdir)) { + if (RMDIR(realdir)) { + free(cp1); + free(realdir); + return (ign_err ? SUCCESS : FAIL); + } } else { - if (REMOVE(dir, ign_err)) - return 1; + if (REMOVE(realdir, ign_err)) { + free(cp1); + free(realdir); + return (ign_err ? SUCCESS : FAIL); + } } - if (!nukedirs) - return 0; + if (!nukedirs) { + free(cp1); + free(realdir); + return (SUCCESS); + } while (cp2) { if ((cp2 = strrchr(cp1, '/')) != NULL) *cp2 = '\0'; - if (!isemptydir(dir)) - return 0; - if (RMDIR(dir) && !ign_err) { - if (!fexists(dir)) - warnx("directory '%s' doesn't exist", dir); - else - return 1; + if (!isemptydir(realdir)) { + free(cp1); + free(realdir); + return (SUCCESS); + } + if (RMDIR(realdir) && !ign_err) { + if (!fexists(realdir)) { + warnx("directory '%s' doesn't exist", realdir); + free(cp1); + free(realdir); + return (SUCCESS); + } else { + free(cp1); + free(realdir); + return (FAIL); + } } /* back up the pathname one component */ if (cp2) { - cp1 = strdup(dir); + free(cp1); + cp1 = strdup(realdir); + if (cp1 == NULL) { + warnx("Couldn't allocate enough memory\n"); + return (ign_err ? SUCCESS : FAIL); + } } } - return 0; + free(cp1); + free(realdir); + return (SUCCESS); } +