Date: Sun, 28 Mar 2010 05:39:21 GMT From: Garrett Cooper <gcooper@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 176181 for review Message-ID: <201003280539.o2S5dLAa067780@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003280539.o2S5dLAa067780>