file.c (106136) | file.c (106491) |
---|---|
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 * Miscellaneous 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 * Miscellaneous file access utilities. 18 * 19 */ 20 21#include <sys/cdefs.h> |
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/lib/file.c 106136 2002-10-29 12:14:31Z des $"); | 22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/lib/file.c 106491 2002-11-06 08:57:03Z obrien $"); |
23 24#include "lib.h" 25#include <err.h> 26#include <fetch.h> 27#include <pwd.h> 28#include <time.h> 29#include <sys/wait.h> 30 --- 101 unchanged lines hidden (view full) --- 132 return FALSE; 133} 134 135#define HOSTNAME_MAX 64 136/* 137 * Try and fetch a file by URL, returning the directory name for where 138 * it's unpacked, if successful. 139 */ | 23 24#include "lib.h" 25#include <err.h> 26#include <fetch.h> 27#include <pwd.h> 28#include <time.h> 29#include <sys/wait.h> 30 --- 101 unchanged lines hidden (view full) --- 132 return FALSE; 133} 134 135#define HOSTNAME_MAX 64 136/* 137 * Try and fetch a file by URL, returning the directory name for where 138 * it's unpacked, if successful. 139 */ |
140char * 141fileGetURL(const char *base, const char *spec) 142{ 143 char *cp, *rp; 144 char fname[FILENAME_MAX]; 145 char pen[FILENAME_MAX]; 146 char buf[8192]; 147 FILE *ftp; 148 pid_t tpid; 149 int pfd[2], pstat, r, w; 150 char *hint; 151 int fd; | |
152 | 140 |
153 rp = NULL; 154 /* Special tip that sysinstall left for us */ 155 hint = getenv("PKG_ADD_BASE"); 156 if (!isURL(spec)) { 157 if (!base && !hint) 158 return NULL; 159 /* 160 * We've been given an existing URL (that's known-good) and now we need 161 * to construct a composite one out of that and the basename we were 162 * handed as a dependency. 163 */ 164 if (base) { 165 strcpy(fname, base); 166 /* 167 * Advance back two slashes to get to the root of the package 168 * hierarchy 169 */ 170 cp = strrchr(fname, '/'); 171 if (cp) { 172 *cp = '\0'; /* chop name */ 173 cp = strrchr(fname, '/'); 174 } 175 if (cp) { 176 *(cp + 1) = '\0'; 177 strcat(cp, "All/"); 178 strcat(cp, spec); 179 /* XXX: need to handle .tgz also */ 180 strcat(cp, ".tbz"); 181 } 182 else 183 return NULL; 184 } 185 else { 186 /* 187 * Otherwise, we've been given an environment variable hinting 188 * at the right location from sysinstall 189 */ 190 strcpy(fname, hint); 191 strcat(fname, spec); 192 /* XXX: need to handle .tgz also */ 193 strcat(fname, ".tbz"); 194 } 195 } 196 else 197 strcpy(fname, spec); 198 199 if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) { 200 printf("Error: FTP Unable to get %s: %s\n", 201 fname, fetchLastErrString); 202 return NULL; 203 } 204 205 if (isatty(0) || Verbose) 206 printf("Fetching %s...", fname), fflush(stdout); 207 pen[0] = '\0'; 208 if ((rp = make_playpen(pen, 0)) == NULL) { 209 printf("Error: Unable to construct a new playpen for FTP!\n"); 210 fclose(ftp); 211 return NULL; 212 } 213 if (pipe(pfd) == -1) { 214 warn("pipe()"); 215 cleanup(0); 216 exit(2); 217 } 218 if ((tpid = fork()) == -1) { 219 warn("pipe()"); 220 cleanup(0); 221 exit(2); 222 } 223 if (!tpid) { 224 dup2(pfd[0], 0); 225 for (fd = getdtablesize() - 1; fd >= 3; --fd) 226 close(fd); 227 /* XXX: need to handle .tgz also */ 228 execl("/usr/bin/tar", "tar", Verbose ? "-xjvf" : "-xjf", "-", 229 (char *)0); 230 _exit(2); 231 } 232 close(pfd[0]); 233 for (;;) { 234 if ((r = fread(buf, 1, sizeof buf, ftp)) < 1) 235 break; 236 if ((w = write(pfd[1], buf, r)) != r) 237 break; 238 } 239 if (ferror(ftp)) 240 warn("warning: error reading from server"); 241 fclose(ftp); 242 close(pfd[1]); 243 if (w == -1) 244 warn("warning: error writing to tar"); 245 tpid = waitpid(tpid, &pstat, 0); 246 if (Verbose) 247 printf("tar command returns %d status\n", WEXITSTATUS(pstat)); 248 if (rp && (isatty(0) || Verbose)) 249 printf(" Done.\n"); 250 return rp; 251} 252 | |
253char * 254fileFindByPath(const char *base, const char *fname) 255{ 256 static char tmp[FILENAME_MAX]; 257 char *cp; 258 const char *suffixes[] = {".tbz", ".tgz", ".tar", NULL}; 259 int i; 260 --- 277 unchanged lines hidden --- | 141char * 142fileFindByPath(const char *base, const char *fname) 143{ 144 static char tmp[FILENAME_MAX]; 145 char *cp; 146 const char *suffixes[] = {".tbz", ".tgz", ".tar", NULL}; 147 int i; 148 --- 277 unchanged lines hidden --- |