diff options
author | jlam <jlam> | 2003-10-29 23:00:27 +0000 |
---|---|---|
committer | jlam <jlam> | 2003-10-29 23:00:27 +0000 |
commit | b39c0ed13a11ddba9e47df2578f86c619c011410 (patch) | |
tree | e12a2ff56e751449aac7cf296f2549c7786aea2c /pkgtools/pkg_install/files/lib/file.c | |
parent | 6a4a295bd4ec7656a3f7f557ca4c1d96ded79feb (diff) | |
download | pkgsrc-b39c0ed13a11ddba9e47df2578f86c619c011410.tar.gz |
Sync pkgtools/pkg_install with src/usr.sbin/pkg_install from 20031003.
New features include fetching binary packages using HTTP (thanks wiz!)
and some minor speed optimizations for pkg_delete.
Diffstat (limited to 'pkgtools/pkg_install/files/lib/file.c')
-rw-r--r-- | pkgtools/pkg_install/files/lib/file.c | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/pkgtools/pkg_install/files/lib/file.c b/pkgtools/pkg_install/files/lib/file.c index 18a3d74593a..1da29045f37 100644 --- a/pkgtools/pkg_install/files/lib/file.c +++ b/pkgtools/pkg_install/files/lib/file.c @@ -1,4 +1,4 @@ -/* $NetBSD: file.c,v 1.8 2003/09/23 13:22:41 grant Exp $ */ +/* $NetBSD: file.c,v 1.9 2003/10/29 23:00:28 jlam Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -11,7 +11,7 @@ #if 0 static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp"; #else -__RCSID("$NetBSD: file.c,v 1.8 2003/09/23 13:22:41 grant Exp $"); +__RCSID("$NetBSD: file.c,v 1.9 2003/10/29 23:00:28 jlam Exp $"); #endif #endif @@ -37,12 +37,19 @@ __RCSID("$NetBSD: file.c,v 1.8 2003/09/23 13:22:41 grant Exp $"); #include "lib.h" +#if HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif + #if HAVE_ASSERT_H #include <assert.h> #endif #if HAVE_ERR_H #include <err.h> #endif +#if HAVE_GLOB_H +#include <glob.h> +#endif #if HAVE_NETDB_H #include <netdb.h> #endif @@ -535,6 +542,40 @@ move_file(char *dir, char *fname, char *to) } } +void +remove_files(const char *path, const char *pattern) +{ + char fpath[FILENAME_MAX]; + glob_t globbed; + int i; + + (void) snprintf(fpath, sizeof(fpath), "%s/%s", path, pattern); + if ((i=glob(fpath, GLOB_NOSORT, NULL, &globbed)) != 0) { + switch(i) { + case GLOB_NOMATCH: + warn("no files matching ``%s'' found", fpath); + break; + case GLOB_ABORTED: + warn("globbing aborted"); + break; + case GLOB_NOSPACE: + warn("out-of-memory during globbing"); + break; + default: + warn("unknown error during globbing"); + break; + } + return; + } + + /* deleting globbed files */ + for (i=0; i<globbed.gl_pathc; i++) + if (unlink(globbed.gl_pathv[i]) < 0) + warn("can't delete ``%s''", globbed.gl_pathv[i]); + + return; +} + /* * Unpack a tar file */ @@ -659,12 +700,12 @@ format_cmd(char *buf, size_t size, char *fmt, char *dir, char *name) } switch (*fmt) { case 'F': - strnncpy(bufp, size - (int) (bufp - buf), name, strlen(name)); + strlcpy(bufp, name, size - (int) (bufp - buf)); bufp += strlen(bufp); break; case 'D': - strnncpy(bufp, size - (int) (bufp - buf), dir, strlen(dir)); + strlcpy(bufp, dir, size - (int) (bufp - buf)); bufp += strlen(bufp); break; @@ -673,7 +714,8 @@ format_cmd(char *buf, size_t size, char *fmt, char *dir, char *name) if ((cp = strrchr(scratch, '/')) == (char *) NULL) { cp = scratch; } - strnncpy(bufp, size - (int) (bufp - buf), scratch, (size_t) (cp - scratch)); + *cp = '\0'; + strlcpy(bufp, scratch, size - (int) (bufp - buf)); bufp += strlen(bufp); break; @@ -684,7 +726,7 @@ format_cmd(char *buf, size_t size, char *fmt, char *dir, char *name) } else { cp++; } - strnncpy(bufp, size - (int) (bufp - buf), cp, strlen(cp)); + strlcpy(bufp, cp, size - (int) (bufp - buf)); bufp += strlen(bufp); break; |