Date: Mon, 1 Nov 2010 03:10:39 GMT From: David Forsythe <dforsyth@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 185291 for review Message-ID: <201011010310.oA13Adpx089632@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@185291?ac=10 Change 185291 by dforsyth@skunk on 2010/11/01 03:10:07 Drop add and validate from the build. Add needs to be completely rewritten and validate needs to be deleted all together. Affected files ... .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.h#10 edit .. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/Makefile#3 edit .. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_add/pkg_add.c#5 edit .. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_validate/validate.c#3 edit Differences ... ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.h#10 (text+ko) ==== @@ -19,6 +19,7 @@ #define PKG_FATAL (-2) #include "pkg_types.h" +#include <stdio.h> struct pkg_db; @@ -65,10 +66,9 @@ int pkg_db_remove(struct pkg_db *, struct pkg *); /* - * When you're done with a package, release its resources using pkg_finish. The - * db argument is the database in which this package exists. + * When you're done with a package, release its resources using pkg_finish. */ -int pkg_finish(struct pkg_db *, struct pkg *); +int pkg_finish(struct pkg *); /* * Retrieve the name of a package. @@ -153,13 +153,19 @@ struct pkg *pkg_archive_open(struct pkg_archive *, const char *); -struct pkg_repo *pkg_repo_create(void); +struct pkg_repo *pkg_repo_create(void); + +int pkg_repo_open(struct pkg_repo *, const char *); + +FILE *pkg_repo_fetch(struct pkg_repo *, const char *, + uint32_t *); + +int pkg_repo_close(struct pkg_repo *); -int pkg_repo_open(struct pkg_repo *, - const char *); +int pkg_repo_finish(struct pkg_repo *); /* I hope to make this disappear. */ -int pkg_parse(struct pkg *, char *, - const char *); +int pkg_parse(struct pkg *, char *, + const char *); #endif ==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/Makefile#3 (text+ko) ==== @@ -3,5 +3,5 @@ # See LICENSE file for license details. # -SUBDIR= pkg_dump pkg_info pkg_delete pkg_add pkg_validate +SUBDIR= pkg_dump pkg_info pkg_delete .include <bsd.subdir.mk> ==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_add/pkg_add.c#5 (text+ko) ==== @@ -34,10 +34,7 @@ #define HAVE_URL 0x10000000 const char *prefix; -const char *ad; /* Archive directory. */ -struct pkg_database *db; -struct pkg_repository *rp; uint32_t flags; struct pkg_target { @@ -106,12 +103,13 @@ NULL }; -static void parse_arguments(int, char **); -static int pkg_add(struct pkg_repository *, struct pkg_database *, - struct target_queue *, const char *, uint32_t, - void (*) (const char *, size_t, size_t)); -static void clean_up(int); -static void usage(void); +static void parse_arguments(int, char **); +static int pkg_add(struct pkg_repo *, struct pkg_db *, + struct target_queue *, const char *, uint32_t, + void (*) (const char *, size_t, size_t)); +static void clean_up(int); +static void usage(void); +static void show_progress(const char *, size_t, size_t); static void usage(void) @@ -191,28 +189,23 @@ } static int -check_installed(struct pkg_database *_db, struct pkg *p, const char *name) +check_installed(struct pkg_db *db, const char *name) { - pkg_database_rewind(_db); + struct pkg *pkg; printf("check: %s\n", name); - /* XXX: Fix skips. */ - while (pkg_database_get_next_pkg(_db, p, 0) == PKG_OK) { - if (strcmp(pkg_freebsd_get_name(p), name) == 0) { - return (1); - } + + pkg = pkg_db_get(db, name); + if (pkg != NULL) { + pkg_finish(pkg); + return (1); } - struct add_artifact *t; - LIST_FOREACH(t, &test_added, next) { - if (strcmp(t->name, name) == 0) { - return (1); - } - } + return (0); } static void -progress(const char *name, size_t fetched, size_t total) +show_progress(const char *name, size_t fetched, size_t total) { printf("\r%s: %lu/%lu bytes", name, (long unsigned)fetched, (long unsigned)total); @@ -223,15 +216,15 @@ main(int argc, char **argv) { int r; + struct pkg_db *db; + struct pkg_repo *rp; parse_arguments(argc, argv); - ad = "pkgdl"; + db = pkg_db_create(); + rp = pkg_repo_create(); - db = pkg_freebsd_database_create(); - rp = pkg_freebsd_repository_create(); - - r = pkg_add(rp, db, &targets, ad, flags, progress); + r = pkg_add(rp, db, &targets, "stage", flags, show_progress); clean_up(r); /* NOT REACHED. */ @@ -244,6 +237,10 @@ add_package(const char *_pkg, struct pkg_repository *_rp, struct pkg_database *_db, const char *_ad, uint32_t _flags, void (*_progress) (const char *, size_t, size_t)) +static int +add_package(const char *name, struct pkg_repo *rp, struct pkg_db *db, + const char *stage, uint32_t flags, + void (*progress) (const char *, size_t, size_t)); { struct archive *ar; struct archive_entry *ae; @@ -387,7 +384,7 @@ if (buf == NULL) { return (-1); } - bufsz = archive_entry_size(ae); + bufsz = archive_entry_size(ae); } r = archive_read_data(ar, buf, archive_entry_size(ae)); r = pkg_parse(p, buf, archive_entry_pathname(ae)); @@ -436,9 +433,9 @@ */ static int -pkg_add(struct pkg_repository *_rp, struct pkg_database *_db, - struct target_queue *_tq, const char *_ad, uint32_t _flags, - void (*_progress) (const char *, size_t, size_t)) +pkg_add(struct pkg_repo *rp, struct pkg_db *db, struct target_queue *tq, + const char *stage, uint32_t flags, + void (*progress) (const char *, size_t, size_t)) { int r; struct pkg_target *t; @@ -447,84 +444,51 @@ const char *repo_sub; const char *repo_arch; + const char *dbloc; + const char *rploc; + /* * XXX: To be clear: We could stream right to archive_open_FILE(), but * we want a bit of insurance against a lost connection. So we pull * down the entire archive (even when we don't have keep set). */ - /* TODO: Dummy repo. */ + /* Open the pkg_db. */ + dbloc = getenv("PKGDB_DIR"); + if (dbloc == NULL) dbloc = "/var/db/pkg"; + + rploc = getenv("PACKAGEROOT") + if (rploc == NULL) rploc = "ftp://ftp.freebsd.FreeBSD.org"; - if (FLAGGED(_flags, ADD_REMOTE)) { - repo_sub = get_repo_sub_path(); - repo_arch = get_repo_arch(); - if (repo_sub == NULL) { - errx(1, "Can't figure out relver"); - } - /* XXX: We're lying for testing. */ - repo_sub = "/packages-8.1-release"; - rp = pkg_freebsd_repository_create(); - r = 0; - for (int i = 0; repos[i] != NULL; ++i) { - /* O.O */ - strcpy(repo_site, repos[i]); - strcat(repo_site, "/"); - strcat(repo_site, repo_arch); - strcat(repo_site, "/"); - strcat(repo_site, repo_sub); - strcat(repo_site, "/"); + if (pkg_db_open(db, dbloc) != PKG_OK) return (-1); - r = pkg_repository_open(_rp, repo_site, 0); - if (r == PKG_OK) { - break; - } - } -#if 0 - "ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8.1-release/Latest/", - 0); -#endif - } else { - /* - * This is the 'dummy repo' situation. Just set a path and use - * the repository interface to fetch packages. - */ - rp = NULL; - r = 0; -#if 0 - rp = pkg_freebsd_repository_path_create(); - r = 0; -#endif - } -#if 0 - /* XXX: Something I want to play with. */ - else if (FLAGGED(_a->flags, ADD_LOCAL_REPO)){ - rp = pkg_freebsd_repository_local_create(); - r = pkg_repository_open(rp, packages, 0); - } + repo_sub = get_repo_sub_path(); + if (repo_sub == NULL) errx(1, "Can't figure out relver"); + + repo_arch = get_repo_arch(); + if (repo_arch == NULL) errx(1, "Can't figure out arch"); -#endif - if (r != PKG_OK) { - errx(1, "Could not open repository.\n"); - } + STAILQ_FOREACH(t, tq, next) { + /* TODO(dforsyth): Give this some output. */ + if (check_installed(db, t->target)) + if (flags & FORCE) continue; + + if (flags & ADD_REMOTE) { + /* XXX: We cheat for testing. */ + repo_sub = "/packages-8.1-release"; + + sprintf(rploc, "%s/%s/%s", rploc, repo_arch, + repo_sub); + + if (pkg_repo_open(rp, rploc) != PKG_OK) + continue; - pkg_database_open(db, "/var/db/pkg", 0); - STAILQ_FOREACH(t, _tq, next) { -#if 0 - if (check_installed(db, p, t->target)) { - /* TODO: Act on installed. */ - continue; + /* add_package. */ } -#endif - strcpy(name, "Latest/"); - strcat(name, t->name); - if (add_package(name, _rp, _db, _ad, _flags, _progress) < 0) { - warnx("error adding %s", t->name); - break; - } } - pkg_repository_close(rp); - pkg_repository_release(rp); + pkg_db_close(db); + pkg_db_finish(db); return (0); } ==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_validate/validate.c#3 (text+ko) ==== @@ -4,7 +4,6 @@ #include <sys/stat.h> #include <pkg.h> -#include <pkg_freebsd.h> int main(int argc, char **argv)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011010310.oA13Adpx089632>