PERFORCE change 182216 for review
Julien Laffaye
jlaffaye at skunkworks.freebsd.org
Wed Aug 11 18:26:25 UTC 2010
http://p4web.freebsd.org/@@182216?ac=10
Change 182216 by jlaffaye at jlaffaye-chulak on 2010/08/10 19:51:08
Remove dead code.
Re-implement the _TOP environment variable behavior via a global PkgTopDir
(used to find dependencies on local disk).
Affected files ...
.. //depot/projects/soc2010/pkg_complete/lib/libpkg/pkg.h#11 edit
.. //depot/projects/soc2010/pkg_complete/lib/libpkg/url.c#8 edit
.. //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/add.h#7 edit
.. //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/extract.c#15 edit
.. //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/perform.c#14 edit
Differences ...
==== //depot/projects/soc2010/pkg_complete/lib/libpkg/pkg.h#11 (text+ko) ====
@@ -174,7 +174,6 @@
Boolean isempty(const char *);
Boolean issymlink(const char *);
Boolean isURL(const char *);
-const char *fileGetURL(const char *, const char *, int);
int find_package_url(char * restrict, const char *, const char *);
int fetch_archive(const char *, Boolean);
char *fileFindByPath(const char *, const char *);
==== //depot/projects/soc2010/pkg_complete/lib/libpkg/url.c#8 (text+ko) ====
@@ -31,162 +31,6 @@
#include "pkg.h"
/*
- * Try and fetch a file by URL, returning the directory name for where
- * it's unpacked, if successful.
- * XXX (jlaffaye): to be removed when all call to fileGetURL() are converted to
- * fetch_archive()
- */
-const char *
-fileGetURL(const char *base, const char *spec, int keep_package)
-{
- FILE *ftp = NULL;
- const char *rp = NULL;
- char *cp, *hint, *tmp;
- char fname[FILENAME_MAX];
- char pen[FILENAME_MAX];
- char pkg[FILENAME_MAX];
- char buf[8192];
- int fd = -1, pkgfd = -1;
- int pfd[2], pstat, r, w = 0;
- pid_t tpid;
-
- rp = NULL;
- /* Special tip that sysinstall left for us */
- hint = getenv("PKG_ADD_BASE");
- if (!isURL(spec)) {
- /*
- * We've been given an existing URL (that's known-good) and now
- * we need to construct a composite one out of that and the
- * basename we were handed as a dependency.
- */
- if (base != NULL) {
-
- strcpy(fname, base);
-
- /*
- * Advance back two slashes to get to the root of the
- * package hierarchy
- */
- cp = strrchr(fname, '/');
- if (cp) {
- *cp = '\0'; /* chop name */
- cp = strrchr(fname, '/');
- }
- if (cp != NULL) {
- *(cp + 1) = '\0';
- strcat(cp, "All/");
- strcat(cp, spec);
- strcat(cp, ".tbz");
- }
- else
- return (NULL);
- }
- else if (hint != NULL) {
- /*
- * Otherwise, we've been given an environment variable
- * hinting at the right location from sysinstall
- */
- strcpy(fname, hint);
- strcat(fname, spec);
- strcat(fname, ".tbz");
-
- }
- else
- return (NULL);
-
- }
- 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) {
- warn("Error: Unable to open %s", pkg);
- return (NULL);
- }
-
- }
-
- fetchDebug = (Verbose > 0);
- if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
- warnx("Error: Unable to get %s: %s\n", fname,
- fetchLastErrString);
- /* If the fetch fails, yank the package. */
- if (keep_package && unlink(pkg) < 0) {
- warnx("failed to remove partially fetched package: %s",
- pkg);
- }
- return (NULL);
- }
-
- if (isatty(0) || Verbose) {
- printf("Fetching %s...", fname);
- fflush(stdout);
- }
- pen[0] = '\0';
- if ((rp = make_playpen(pen, 0)) == NULL)
- warn("Error: Unable to construct a new playpen for FTP!");
- else if (pipe(pfd) == -1)
- warn("pipe()");
- else
- switch ((tpid = fork())) {
- case -1:
- warn("fork()");
- break;
- case 0:
- dup2(pfd[0], 0);
- for (fd = getdtablesize() - 1; fd >= 3; --fd)
- close(fd);
- execl("/usr/bin/tar", "tar",
- Verbose ? "-xpjvf" : "-xpjf", "-", (char *)0);
- _exit(2);
- default:
- close(pfd[0]);
-
- for (;;) {
-
- if ((r = fread(buf, 1, sizeof(buf), ftp)) < 1)
- break;
- if ((w = write(pfd[1], buf, r)) != r)
- break;
- if (keep_package)
- if ((w = write(pkgfd, buf, r)) != r)
- break;
-
- }
- if (w == -1)
- warn("warning: error writing to tar");
- if (ferror(ftp))
- warn("warning: error reading from server");
-
- close(pfd[1]);
- tpid = waitpid(tpid, &pstat, 0);
- if (Verbose)
- printf("tar command returned %d status\n",
- WEXITSTATUS(pstat));
- if (rp != NULL && (isatty(0) || Verbose))
- printf(" Done.\n");
- break;
- }
-
- if (0 < fd)
- close(fd);
- if (ftp != NULL)
- fclose(ftp);
- if (0 < pkgfd)
- close(pkgfd);
-
- return (rp);
-
-}
-
-/*
* Given a know-good URL `base', construct the URL to fetch `pkgname'.
* The resulting URL is stored in a fixed buffer of size MAXPATHLEN
* pointed by `p'.
==== //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/add.h#7 (text+ko) ====
@@ -41,6 +41,7 @@
extern Boolean KeepPackage;
extern Boolean IgnoreDeps;
extern add_mode_t AddMode;
+extern char PkgTopDir[PATH_MAX];
int mkdirs(char *path);
int extract_package(struct archive *, Package *, const char *);
==== //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/extract.c#15 (text+ko) ====
@@ -248,7 +248,7 @@
if (ext == NULL)
ext = ".tbz";
snprintf(path, FILENAME_MAX, "%s/%s%s",
- getenv("_TOP"), p->name, ext);
+ PkgTopDir, p->name, ext);
if (fexists(path))
cp = path;
else
==== //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/perform.c#14 (text+ko) ====
@@ -38,6 +38,8 @@
extern char db_dir_tmp[FILENAME_MAX];
extern char db_dir[FILENAME_MAX];
+char PkgTopDir[PATH_MAX];
+
int
pkg_perform(char **pkgs)
{
@@ -47,11 +49,15 @@
if (register_cleanup_handler(cleanup, NULL, NULL, 0) == -1)
err(EXIT_FAILURE, "failed to initialize cleanup exit handler");
- if (AddMode == SLAVE)
+ if (AddMode == SLAVE) {
+ PkgTopDir[0] = '\0';
err_cnt = pkg_do(NULL);
+ }
else
- for (i = 0; pkgs[i]; i++)
+ for (i = 0; pkgs[i]; i++) {
+ PkgTopDir[0] = '\0';
err_cnt += pkg_do(pkgs[i]);
+ }
return err_cnt;
}
@@ -93,6 +99,12 @@
retcode = 1;
goto cleanup;
}
+ if (PkgTopDir[0] == '\0')
+ if (realpath(dirname(fname), PkgTopDir) == NULL) {
+ warn("realpath()");
+ retcode = 1;
+ goto cleanup;
+ }
}
}
@@ -133,86 +145,6 @@
if (a != NULL)
archive_read_finish(a);
return (retcode);
-
-# if 0
- /* Are we coming in for a second pass, everything already extracted? */
- if (!pkg) {
- fgets(playpen, FILENAME_MAX, stdin);
- playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */
- if (chdir(playpen) == -1) {
- warnx("pkg_add in SLAVE mode can't chdir to %s", playpen);
- return 1;
- }
- if (read_plist(&Plist, fileno(stdin)) != 0)
- return 1;
- where_to = playpen;
- }
- /* Nope - do it now */
- else {
- /* Is it an ftp://foo.bar.baz/file.t[bg]z specification? */
- if (isURL(pkg)) {
- if (!(where_to = fileGetURL(NULL, pkg, KeepPackage))) {
- warnx("unable to fetch '%s' by URL", pkg);
- cleanup();
- return 1;
- }
- cfile = open(CONTENTS_FNAME, O_RDONLY);
- if (cfile == -1) {
- warnx(
- "unable to open table of contents file '%s' - not a package?",
- CONTENTS_FNAME);
- goto bomb;
- }
- rc = read_plist(&Plist, cfile);
- close(cfile);
- if (rc != 0)
- goto bomb;
- }
- else {
-
- /*
- * If TRUE: We have to extract the whole thing to disk because
- * this could be our one and only shot to do so...
- */
- Boolean extract_whole_archive_from_stdin = FALSE;
-
- if (strcmp(pkg, "-") == 0)
- extract_whole_archive_from_stdin = TRUE;
-
- /* Since we can call ourselves recursively, keep notes on where we
-came from */
- if (!getenv("_TOP"))
- setenv("_TOP", where_to, 1);
- if (extract_whole_archive_from_stdin == TRUE) {
- if (unpack_to_disk(NULL, NULL) == 0)
- cfile = open(CONTENTS_FNAME, O_RDONLY);
- else {
- warnx("unable to extract table of contents file from '%s' "
- "- not a package?", pkg);
- }
- } else
- cfile = unpack_to_fd(pkg, CONTENTS_FNAME);
-
- if (cfile == -1) {
- warnx("unable to open table of contents file '%s' - not a "
- "package?", CONTENTS_FNAME);
- goto bomb;
- }
- rc = read_plist(&Plist, cfile);
- (void) close(cfile);
- if (rc != 0)
- goto bomb;
- }
-
- /* If we're running in MASTER mode, just output the plist and return */
- if (AddMode == MASTER) {
- printf("%s\n", where_playpen());
- if (write_plist(&Plist, stdout) != 0)
- return 1;
- return 0;
- }
- }
-#endif
}
void
More information about the p4-projects
mailing list