PERFORCE change 185248 for review
David Forsythe
dforsyth at FreeBSD.org
Sat Oct 30 19:35:00 UTC 2010
http://p4web.freebsd.org/@@185248?ac=10
Change 185248 by dforsyth at skunk on 2010/10/30 19:34:47
start bringing back lazy loading-ish behavior.
Affected files ...
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.c#7 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.h#7 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.c#10 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_pkg.h#9 delete
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_types.h#2 edit
.. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_add/pkg_add.c#4 edit
.. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/pkg_info.c#6 edit
Differences ...
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.c#7 (text+ko) ====
@@ -76,9 +76,9 @@
{ 0, NULL, NULL },
};
-static int fbsd_directorydb_read_pkg(
- struct _directorydb *, struct pkg *);
-int fbsd_directorydb_finish(struct pkg_db *,
+static int fbsd_directorydb_read_pkg(struct _directorydb *,
+ struct pkg *, uint32_t);
+int fbsd_directorydb_finish(struct pkg_db *,
struct pkg *);
static char *read_file(const char *);
static int _read_plist_cmp(struct _read_plist *,
@@ -87,6 +87,12 @@
static void fbsd_directorydb_pkg_setup(struct pkg_db *,
struct pkg *, const char *);
+static int fbsd_directorydb_read_name(struct pkg *);
+static int fbsd_directorydb_read_origin(struct pkg *);
+static int fbsd_directorydb_read_comment(struct pkg *);
+static int fbsd_directorydb_read_format_revision(struct pkg *);
+static int fbsd_directorydb_read_description(struct pkg *);
+
RB_GENERATE_STATIC(plist_head, _read_plist, entry, _read_plist_cmp);
#define PKG_DIRDB_MAGIC 0x11111111
@@ -102,6 +108,17 @@
#define _pkg_check_magic(p) assert(p->magic == PKG_DIRDB_MAGIC)
#define _db_check_magic(db) assert(db->magic == DB_DIRDB_MAGIC)
+#define READ_FUNCTION(fn_name, src_mask) \
+static int \
+fn_name(struct pkg *pkg) \
+{ \
+ struct pkg_db *db; \
+ struct _directorydb *d; \
+ db = pkg->source; \
+ d = db->internal; \
+ return (fbsd_directorydb_read_pkg(d, pkg, src_mask)); \
+}
+
static int
_read_plist_cmp(struct _read_plist *a, struct _read_plist *b)
{
@@ -191,6 +208,15 @@
pkg->magic = PKG_DIRDB_MAGIC;
pkg->source = db;
strcpy(pkg->key, key);
+
+ /* Set up our callbacks. */
+ pkg->read_name = fbsd_directorydb_read_name;
+ pkg->read_origin = fbsd_directorydb_read_origin;
+ pkg->read_format_revision = fbsd_directorydb_read_format_revision;
+
+ pkg->read_comment = fbsd_directorydb_read_comment;
+
+ pkg->read_description = fbsd_directorydb_read_description;
pkg->add_file = fbsd_directorydb_add_file;
@@ -223,12 +249,7 @@
pkg = pkg_alloc();
/* XXX: I should just do a get here. */
fbsd_directorydb_pkg_setup(db, pkg, ents[i]->d_name);
- /* XXX: For now just hit every mask. */
- if (fbsd_directorydb_read_pkg(d, pkg) != PKG_OK) {
- /* Do clean up */
- printf("bad read\n");
- return (NULL);
- }
+
TAILQ_INSERT_TAIL(list, pkg, next);
free(ents[i]);
}
@@ -313,7 +334,6 @@
}
fbsd_directorydb_pkg_setup(db, pkg, key);
- fbsd_directorydb_read_pkg(d, pkg);
return (PKG_OK);
}
@@ -329,8 +349,15 @@
return (PKG_OK);
}
+READ_FUNCTION(fbsd_directorydb_read_name, CONTENTS);
+READ_FUNCTION(fbsd_directorydb_read_origin, CONTENTS);
+READ_FUNCTION(fbsd_directorydb_read_format_revision, CONTENTS);
+READ_FUNCTION(fbsd_directorydb_read_comment, COMMENT);
+READ_FUNCTION(fbsd_directorydb_read_description, DESCRIPTION);
+
static int
-fbsd_directorydb_read_pkg(struct _directorydb *d, struct pkg *pkg)
+fbsd_directorydb_read_pkg(struct _directorydb *d, struct pkg *pkg,
+ uint32_t mask)
{
struct pkg_info *pi;
char path[PATH_MAX];
@@ -338,13 +365,15 @@
int r;
for (pi = pkg_entries; pi->info_name != NULL; pi++) {
- _pkg_util_path_join(path, d->path, pkg->key);
- _pkg_util_path_join(path, path, pi->file_name);
-
- if ((data = read_file(path)) == NULL) continue;
+ if (mask & pi->info_mask) {
+ _pkg_util_path_join(path, d->path, pkg->key);
+ _pkg_util_path_join(path, path, pi->file_name);
+
+ if ((data = read_file(path)) == NULL) continue;
- r = fbsd_plist_parse(pkg, data, pi->info_name);
- if (r != PKG_OK) return (r);
+ r = fbsd_plist_parse(pkg, data, pi->info_name);
+ if (r != PKG_OK) return (r);
+ }
}
return (PKG_OK);
@@ -395,3 +424,4 @@
return (sb.st_uid);
}
+
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.h#7 (text+ko) ====
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.c#10 (text+ko) ====
@@ -91,7 +91,7 @@
void
_pkg_set_origin(struct pkg *pkg, const char *origin)
{
- pkg->origin = strndup(origin, PATH_MAX);
+ strncpy(pkg->origin, origin, PATH_MAX);
}
void
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_types.h#2 (text+ko) ====
@@ -10,53 +10,53 @@
struct pkg {
/* The magic value will let us know what type of underlying interface
* we're dealing with. */
- unsigned int magic;
- char key[PATH_MAX];
- void *source; /* XXX: Make this a union. */
+ unsigned int magic;
+ char key[PATH_MAX];
+ void *source; /* XXX: Make this a union. */
- void (*read_origin) (struct pkg *);
- char *origin;
+ int (*read_origin) (struct pkg *);
+ char origin[PATH_MAX];
- void (*read_name) (struct pkg *);
- char name[PATH_MAX];
+ int (*read_name) (struct pkg *);
+ char name[PATH_MAX];
- void (*read_srcdir) (struct pkg *);
- char srcdir[PATH_MAX];
+ int (*read_srcdir) (struct pkg *);
+ char srcdir[PATH_MAX];
- void (*read_format_revision) (struct pkg *);
- char format_revision[256];
+ int (*read_format_revision) (struct pkg *);
+ char format_revision[256];
- void (*read_comment) (struct pkg *);
+ int (*read_comment) (struct pkg *);
/* This is 128 for now, I'd like it down at 80. */
- char comment[128];
+ char comment[128];
- void (*read_description) (struct pkg *);
- char *description;
+ int (*read_description) (struct pkg *);
+ char *description;
- void (*read_files) (struct pkg *);
- struct pkg_file_list *files;
+ int (*read_files) (struct pkg *);
+ struct pkg_file_list *files;
- void (*read_depends) (struct pkg *);
- struct pkg_depend_list *depends;
+ int (*read_depends) (struct pkg *);
+ struct pkg_depend_list *depends;
- void (*read_conflicts) (struct pkg *);
+ int (*read_conflicts) (struct pkg *);
struct pkg_conflict_list *conflicts;
- void (*read_reqbys) (struct pkg *);
- struct pkg_reqby_list *reqbys;
+ int (*read_reqbys) (struct pkg *);
+ struct pkg_reqby_list *reqbys;
- int (*has_file) (struct pkg *);
- int (*has_depend) (struct pkg *);
- int (*has_conflict) (struct pkg *);
+ int (*has_file) (struct pkg *);
+ int (*has_depend) (struct pkg *);
+ int (*has_conflict) (struct pkg *);
- struct pkg_file *(*add_file) (struct pkg *, const char *,
+ struct pkg_file *(*add_file) (struct pkg *, const char *,
const char *);
- struct pkg_depend *(*add_depend) (struct pkg *, const char *,
- const char *);
- struct pkg_conflict *(*add_conflict) (struct pkg *, const char *,
- const char *);
+ struct pkg_depend *(*add_depend) (struct pkg *, const char *,
+ const char *);
+ struct pkg_conflict *(*add_conflict) (struct pkg *, const char *,
+ const char *);
struct pkg_reqby *(*add_reqby) (struct pkg *, const char *,
- const char *);
+ const char *);
int (*remove_file) (struct pkg *,
struct pkg_file *);
==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_add/pkg_add.c#4 (text+ko) ====
@@ -19,7 +19,6 @@
#include <libgen.h>
#include <pkg.h>
-#include <pkg_freebsd.h>
#define ADD_NODEPS 0x00000001
#define ADD_NORECORD 0x00000002
==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/pkg_info.c#6 (text+ko) ====
@@ -700,13 +700,13 @@
}
if (_c->show_flags & SHOW_ORIGIN) {
- if (_c->quiet) printf("%sOrigin:\n", _c->info_prefix);
+ if (!_c->quiet) printf("%sOrigin:\n", _c->info_prefix);
printf("%s\n", pkg_origin(pkg));
}
if (_c->show_flags & SHOW_FMTREV) {
- if (_c->quiet)
+ if (!_c->quiet)
printf("%sFormat revision:\n", _c->info_prefix);
printf("%s\n", pkg_format_revision(pkg));
More information about the p4-projects
mailing list