summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authorflz <flz@FreeBSD.org>2006-01-09 18:27:21 +0000
committerflz <flz@FreeBSD.org>2006-01-09 18:27:21 +0000
commitc97d1806500049ffe6c3e8091ab4cfb4c997281e (patch)
tree1d907422a2b7e64739038fb6d8d33e072dc613d3 /usr.sbin/pkg_install/lib
parent93d7e294fcdb0d064bd15e9208026d662d5c43ce (diff)
downloadFreeBSD-src-c97d1806500049ffe6c3e8091ab4cfb4c997281e.zip
FreeBSD-src-c97d1806500049ffe6c3e8091ab4cfb4c997281e.tar.gz
Add -K option to pkg_add and pkg_info.
This option saves packages to PKGDIR (if defined or current directory by default) as they are downloaded. Silent a warning when -n is used and package has a +DISPLAY file. Approved by: krion MFC after: 1 week
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/lib.h2
-rw-r--r--usr.sbin/pkg_install/lib/url.c29
2 files changed, 27 insertions, 4 deletions
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h
index cdbfe00..2227f85 100644
--- a/usr.sbin/pkg_install/lib/lib.h
+++ b/usr.sbin/pkg_install/lib/lib.h
@@ -172,7 +172,7 @@ Boolean isfile(const char *);
Boolean isempty(const char *);
Boolean issymlink(const char *);
Boolean isURL(const char *);
-char *fileGetURL(const char *, const char *);
+char *fileGetURL(const char *, const char *, int);
char *fileFindByPath(const char *, const char *);
char *fileGetContents(const char *);
void write_file(const char *, const char *);
diff --git a/usr.sbin/pkg_install/lib/url.c b/usr.sbin/pkg_install/lib/url.c
index 41017b4..43f2d81 100644
--- a/usr.sbin/pkg_install/lib/url.c
+++ b/usr.sbin/pkg_install/lib/url.c
@@ -24,24 +24,27 @@ __FBSDID("$FreeBSD$");
#include "lib.h"
#include <err.h>
#include <fetch.h>
+#include <libgen.h>
#include <sys/wait.h>
+#include <stdio.h>
/*
* Try and fetch a file by URL, returning the directory name for where
* it's unpacked, if successful.
*/
char *
-fileGetURL(const char *base, const char *spec)
+fileGetURL(const char *base, const char *spec, int keep_package)
{
- char *cp, *rp;
+ char *cp, *rp, *tmp;
char fname[FILENAME_MAX];
char pen[FILENAME_MAX];
+ char pkg[FILENAME_MAX];
char buf[8192];
FILE *ftp;
pid_t tpid;
int pfd[2], pstat, r, w = 0;
char *hint;
- int fd;
+ int fd, pkgfd = 0;
rp = NULL;
/* Special tip that sysinstall left for us */
@@ -95,6 +98,19 @@ fileGetURL(const char *base, const char *spec)
else
strcpy(fname, spec);
+ if (keep_package) {
+ tmp = getenv("PKGDIR");
+ strlcpy(pkg, tmp ? tmp : ".", sizeof(pkg));
+ tmp = basename(fname);
+ strlcat(pkg, "/", sizeof(pkg));
+ strlcat(pkg, tmp, sizeof(pkg));
+ if ((pkgfd = open(pkg, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
+ printf("Error: Unable to open %s\n", pkg);
+ perror("open");
+ return NULL;
+ }
+ }
+
if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
printf("Error: FTP Unable to get %s: %s\n",
fname, fetchLastErrString);
@@ -138,10 +154,17 @@ fileGetURL(const char *base, const char *spec)
break;
if ((w = write(pfd[1], buf, r)) != r)
break;
+ if (keep_package) {
+ if ((w = write(pkgfd, buf, r)) != r)
+ break;
+ }
}
if (ferror(ftp))
warn("warning: error reading from server");
fclose(ftp);
+ if (keep_package) {
+ close(pkgfd);
+ }
close(pfd[1]);
if (w == -1)
warn("warning: error writing to tar");
OpenPOWER on IntegriCloud