PERFORCE change 176181 for review
Garrett Cooper
gcooper at FreeBSD.org
Sun Mar 28 05:39:22 UTC 2010
http://p4web.freebsd.org/chv.cgi?CH=176181
Change 176181 by gcooper at 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);
}
}
More information about the p4-projects
mailing list