Deleted Added
full compact
url.c (113587) url.c (131285)
1/*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 5 unchanged lines hidden (view full) ---

14 * Jordan K. Hubbard
15 * 18 July 1993
16 *
17 * URL file access utilities.
18 *
19 */
20
21#include <sys/cdefs.h>
1/*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 5 unchanged lines hidden (view full) ---

14 * Jordan K. Hubbard
15 * 18 July 1993
16 *
17 * URL file access utilities.
18 *
19 */
20
21#include <sys/cdefs.h>
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/lib/url.c 113587 2003-04-17 03:51:06Z rwatson $");
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/lib/url.c 131285 2004-06-29 19:06:42Z eik $");
23
24#include "lib.h"
25#include <err.h>
26#include <fetch.h>
27#include <sys/wait.h>
28
29/*
30 * Try and fetch a file by URL, returning the directory name for where
31 * it's unpacked, if successful.
32 */
33char *
34fileGetURL(const char *base, const char *spec)
35{
36 char *cp, *rp;
37 char fname[FILENAME_MAX];
38 char pen[FILENAME_MAX];
39 char buf[8192];
40 FILE *ftp;
41 pid_t tpid;
23
24#include "lib.h"
25#include <err.h>
26#include <fetch.h>
27#include <sys/wait.h>
28
29/*
30 * Try and fetch a file by URL, returning the directory name for where
31 * it's unpacked, if successful.
32 */
33char *
34fileGetURL(const char *base, const char *spec)
35{
36 char *cp, *rp;
37 char fname[FILENAME_MAX];
38 char pen[FILENAME_MAX];
39 char buf[8192];
40 FILE *ftp;
41 pid_t tpid;
42 int pfd[2], pstat, r, w;
42 int pfd[2], pstat, r, w = 0;
43 char *hint;
44 int fd;
45
46 rp = NULL;
47 /* Special tip that sysinstall left for us */
48 hint = getenv("PKG_ADD_BASE");
49 if (!isURL(spec)) {
50 if (!base && !hint)

--- 13 unchanged lines hidden (view full) ---

64 if (cp) {
65 *cp = '\0'; /* chop name */
66 cp = strrchr(fname, '/');
67 }
68 if (cp) {
69 *(cp + 1) = '\0';
70 strcat(cp, "All/");
71 strcat(cp, spec);
43 char *hint;
44 int fd;
45
46 rp = NULL;
47 /* Special tip that sysinstall left for us */
48 hint = getenv("PKG_ADD_BASE");
49 if (!isURL(spec)) {
50 if (!base && !hint)

--- 13 unchanged lines hidden (view full) ---

64 if (cp) {
65 *cp = '\0'; /* chop name */
66 cp = strrchr(fname, '/');
67 }
68 if (cp) {
69 *(cp + 1) = '\0';
70 strcat(cp, "All/");
71 strcat(cp, spec);
72 /* XXX: need to handle .tgz also */
72#if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
73 strcat(cp, ".tbz");
73 strcat(cp, ".tbz");
74#else
75 strcat(cp, ".tgz");
76#endif
74 }
75 else
76 return NULL;
77 }
78 else {
79 /*
80 * Otherwise, we've been given an environment variable hinting
81 * at the right location from sysinstall
82 */
83 strcpy(fname, hint);
84 strcat(fname, spec);
77 }
78 else
79 return NULL;
80 }
81 else {
82 /*
83 * Otherwise, we've been given an environment variable hinting
84 * at the right location from sysinstall
85 */
86 strcpy(fname, hint);
87 strcat(fname, spec);
85 /* XXX: need to handle .tgz also */
88#if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
86 strcat(fname, ".tbz");
89 strcat(fname, ".tbz");
90#else
91 strcat(fname, ".tgz");
92#endif
87 }
88 }
89 else
90 strcpy(fname, spec);
91
92 if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
93 printf("Error: FTP Unable to get %s: %s\n",
94 fname, fetchLastErrString);

--- 17 unchanged lines hidden (view full) ---

112 warn("pipe()");
113 cleanup(0);
114 exit(2);
115 }
116 if (!tpid) {
117 dup2(pfd[0], 0);
118 for (fd = getdtablesize() - 1; fd >= 3; --fd)
119 close(fd);
93 }
94 }
95 else
96 strcpy(fname, spec);
97
98 if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
99 printf("Error: FTP Unable to get %s: %s\n",
100 fname, fetchLastErrString);

--- 17 unchanged lines hidden (view full) ---

118 warn("pipe()");
119 cleanup(0);
120 exit(2);
121 }
122 if (!tpid) {
123 dup2(pfd[0], 0);
124 for (fd = getdtablesize() - 1; fd >= 3; --fd)
125 close(fd);
120 /* XXX: need to handle .tgz also */
121 execl("/usr/bin/tar", "tar", Verbose ? "-xjvf" : "-xjf", "-",
122 (char *)0);
126 execl("/usr/bin/tar", "tar",
127#if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
128 Verbose ? "-xjvf" : "-xjf",
129#else
130 Verbose ? "-xzvf" : "-xzf",
131#endif
132 "-", (char *)0);
123 _exit(2);
124 }
125 close(pfd[0]);
126 for (;;) {
127 if ((r = fread(buf, 1, sizeof buf, ftp)) < 1)
128 break;
129 if ((w = write(pfd[1], buf, r)) != r)
130 break;

--- 14 unchanged lines hidden ---
133 _exit(2);
134 }
135 close(pfd[0]);
136 for (;;) {
137 if ((r = fread(buf, 1, sizeof buf, ftp)) < 1)
138 break;
139 if ((w = write(pfd[1], buf, r)) != r)
140 break;

--- 14 unchanged lines hidden ---