From owner-p4-projects@FreeBSD.ORG Sun Mar 28 05:39:22 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4D3111065670; Sun, 28 Mar 2010 05:39:22 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0429C106564A for ; Sun, 28 Mar 2010 05:39:22 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id E57FE8FC08 for ; Sun, 28 Mar 2010 05:39:21 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o2S5dLZs067782 for ; Sun, 28 Mar 2010 05:39:21 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o2S5dLAa067780 for perforce@freebsd.org; Sun, 28 Mar 2010 05:39:21 GMT (envelope-from gcooper@FreeBSD.org) Date: Sun, 28 Mar 2010 05:39:21 GMT Message-Id: <201003280539.o2S5dLAa067780@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 176181 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Mar 2010 05:39:22 -0000 http://p4web.freebsd.org/chv.cgi?CH=176181 Change 176181 by gcooper@gcooper-bayonetta on 2010/03/28 05:38:39 1. Compress isfile and issymlink check. 2. Add a comment to move_file, and just be a bit more pedantic about the results from vsystem, and provide better diags when the function call fails. Affected files ... .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/lib/file.c#2 edit Differences ... ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/lib/file.c#2 (text+ko) ==== @@ -82,9 +82,7 @@ isfile(const char *fname) { struct stat sb; - if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) - return TRUE; - return FALSE; + return (stat(fname, &sb) == 0 && S_ISREG(sb.st_mode) != 0); } /* @@ -108,9 +106,7 @@ issymlink(const char *fname) { struct stat sb; - if (lstat(fname, &sb) != FAIL && S_ISLNK(sb.st_mode)) - return TRUE; - return FALSE; + return (lstat(fname, &sb) == 0 && S_ISLNK(sb.st_mode) != 0); } /* Returns TRUE if file is a URL specification */ @@ -278,18 +274,22 @@ } } +/* + * Move a file -- fname -- to a directory -- to. If fname starts with '/', + * then it's assumed to be an absolute path. + */ void move_file(const char *dir, const char *fname, const char *to) { char cmd[FILENAME_MAX]; if (fname[0] == '/') - snprintf(cmd, FILENAME_MAX, "/bin/mv %s %s", fname, to); + snprintf(cmd, FILENAME_MAX, "/bin/mv %s %s", fname, to); else snprintf(cmd, FILENAME_MAX, "/bin/mv %s/%s %s", dir, fname, to); - if (vsystem(cmd)) { + if (vsystem(cmd) != 0) { cleanup(0); - errx(2, "%s: could not perform '%s'", __func__, cmd); + errx(2, "%s.%s: could not perform '%s'", progname, __func__, cmd); } }