PERFORCE change 185742 for review
David Forsythe
dforsyth at FreeBSD.org
Sat Nov 13 17:19:12 UTC 2010
http://p4web.freebsd.org/@@185742?ac=10
Change 185742 by dforsyth at skunk on 2010/11/13 17:18:40
Add a bunch of finish functions for lists.
Affected files ...
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/conflict.c#3 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/conflict.h#3 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.c#11 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.h#8 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/depend.c#5 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/depend.h#5 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.c#6 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.h#6 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.c#11 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.h#10 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.c#13 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.h#13 edit
.. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_types.h#6 edit
.. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/pkg_info.c#9 edit
Differences ...
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/conflict.c#3 (text+ko) ====
@@ -17,6 +17,32 @@
free(c);
}
+int
+pkg_conflict_finish(struct pkg_conflict *c)
+{
+ pkg_conflict_release(c);
+ return (PKG_OK);
+}
+
+int
+pkg_conflict_list_finish(struct pkg_conflict_list *conflicts)
+{
+ struct pkg_conflict *c;
+ struct pkg_conflict *nc;
+
+ c = TAILQ_FIRST(conflicts);
+ while (c != NULL) {
+ nc = TAILQ_NEXT(c, next);
+ if (pkg_conflict_finish(c) != PKG_OK)
+ return (PKG_NOT_OK);
+ c = nc;
+ }
+
+ free(conflicts);
+
+ return (PKG_OK);
+}
+
void
_pkg_conflict_set_expr(struct pkg_conflict *conflict, const char *expr)
{
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/conflict.h#3 (text+ko) ====
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.c#11 (text+ko) ====
@@ -49,22 +49,24 @@
/* TODO: NULL out callback pointers. */
db->open = fbsd_directorydb_open;
db->close = fbsd_directorydb_close;
- db->all = fbsd_directorydb_all;
+ db->all = fbsd_directorydb_pkgs;
db->get = fbsd_directorydb_get;
return (db);
}
+/*
+ * Finish does a commit before close. Close does not.
+ */
int
pkg_db_finish(struct pkg_db *db)
{
- /* Close if the db is open. */
- if (db->internal != NULL) {
- if (pkg_db_close(db) != PKG_OK) {
- warnx("Could not close pkg_db (%s)\n", db->path);
- return (PKG_NOT_OK);
- }
- }
+ /*
+ * If the db is actually open, we need to call the internal finish
+ * function so that changes are commited.
+ */
+ if (db->internal != NULL)
+ if (db->finish(db) != PKG_OK) return (PKG_NOT_OK);
free(db);
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.h#8 (text+ko) ====
@@ -22,6 +22,7 @@
const char *);
int (*close) (struct pkg_db *);
int (*contains) (struct pkg_db *, const char *);
+ int (*finish) (struct pkg_db *);
int (*get) (struct pkg_db *, struct pkg *,
const char *);
struct pkg_list *(*all) (struct pkg_db *);
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/depend.c#5 (text+ko) ====
@@ -17,6 +17,32 @@
free(d);
}
+int
+pkg_depend_finish(struct pkg_depend *d)
+{
+ pkg_depend_release(d);
+ return (PKG_OK);
+}
+
+int
+pkg_depend_list_finish(struct pkg_depend_list *depends)
+{
+ struct pkg_depend *d;
+ struct pkg_depend *nd;
+
+ d = TAILQ_FIRST(depends);
+ while (d != NULL) {
+ nd = TAILQ_NEXT(d, next);
+ if (pkg_depend_finish(d) != PKG_OK)
+ return (PKG_NOT_OK);
+ d = nd;
+ }
+
+ free(depends);
+
+ return (PKG_OK);
+}
+
const char *
pkg_depend_name(struct pkg_depend *dep)
{
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/depend.h#5 (text+ko) ====
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.c#6 (text+ko) ====
@@ -20,6 +20,32 @@
free(file);
}
+int
+pkg_file_finish(struct pkg_file *file)
+{
+ pkg_file_release(file);
+ return (PKG_OK);
+}
+
+int
+pkg_file_list_finish(struct pkg_file_list *files)
+{
+ struct pkg_file *f;
+ struct pkg_file *nf;
+
+ f = TAILQ_FIRST(files);
+ while (f != NULL) {
+ nf = TAILQ_NEXT(f, next);
+ if (pkg_file_finish(f) != PKG_NOT_OK)
+ return (PKG_NOT_OK);
+ f = nf;
+ }
+
+ free(files);
+
+ return (PKG_OK);
+}
+
const char *
pkg_file_prefix(struct pkg_file *file)
{
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.h#6 (text+ko) ====
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.c#11 (text+ko) ====
@@ -63,7 +63,7 @@
static int fbsd_directorydb_read_pkg(struct _directorydb *,
struct pkg *, uint32_t);
-static int fbsd_directorydb_finish(struct pkg *);
+static int fbsd_directorydb_pkg_finish(struct pkg *);
static char *read_file(const char *);
static void fbsd_directorydb_pkg_setup(struct pkg_db *,
struct pkg *, const char *);
@@ -163,7 +163,6 @@
pkg->read_description = fbsd_directorydb_read_description;
-
pkg->conflicts = NULL;
pkg->depends = NULL;
pkg->files = NULL;
@@ -173,7 +172,7 @@
pkg->add_conflict = fbsd_directorydb_add_conflict;
pkg->add_file = fbsd_directorydb_add_file;
- pkg->finish = fbsd_directorydb_finish;
+ pkg->finish = fbsd_directorydb_pkg_finish;
}
static int
@@ -189,7 +188,7 @@
}
struct pkg_list *
-fbsd_directorydb_all(struct pkg_db *db)
+fbsd_directorydb_pkgs(struct pkg_db *db)
{
struct _directorydb *d;
FTS *ftsp;
@@ -361,7 +360,7 @@
}
int
-fbsd_directorydb_finish(struct pkg *pkg)
+fbsd_directorydb_pkg_finish(struct pkg *pkg)
{
const char *key;
struct pkg_db *db;
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.h#10 (text+ko) ====
@@ -6,16 +6,14 @@
#ifndef __PKGDB_DIRECTORYDB_H__
#define __PKGDB_DIRECTORYDB_H__
-int fbsd_directorydb_add(struct pkg_db *, struct pkg *,
- const char *, const char *, const char *, const char *);
+int fbsd_directorydb_add(struct pkg_db *, struct pkg *, const char *,
+ const char *, const char *, const char *);
/* Test if a key exists. */
-int fbsd_directorydb_contains(struct pkg_db *,
- const char *);
+int fbsd_directorydb_contains(struct pkg_db *, const char *);
/* Populates a pkg with the value from key. */
-int fbsd_directorydb_get(struct pkg_db *, struct pkg *,
- const char *);
+int fbsd_directorydb_get(struct pkg_db *, struct pkg *, const char *);
int fbsd_directorydb_delete(struct pkg_db *, struct pkg *);
@@ -25,11 +23,13 @@
/* Connect. */
int fbsd_directorydb_open(struct pkg_db *, const char *);
+int fbsd_directorydb_finish(struct pkg_db *);
+
/* Quit (nocommit). */
int fbsd_directorydb_close(struct pkg_db *);
/* Returns a pkg_list of all the packages in a database. */
-struct pkg_list *fbsd_directorydb_all(struct pkg_db *);
+struct pkg_list *fbsd_directorydb_pkgs(struct pkg_db *);
/* Returns a newly created file in a package. */
struct pkg_file *fbsd_directorydb_add_file(struct pkg *, const char *,
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.c#13 (text+ko) ====
@@ -47,42 +47,19 @@
void
pkg_release(struct pkg *pkg)
{
- struct pkg_conflict *c, *nc;
- struct pkg_depend *d, *nd;
- struct pkg_file *f, *nf;
+ if (pkg->conflicts != NULL) pkg_conflict_list_finish(pkg->conflicts);
- if (pkg->conflicts != NULL) {
- /* Do tailq deletion. */
- c = TAILQ_FIRST(pkg->conflicts);
- while (c != NULL) {
- nc = TAILQ_NEXT(c, next);
- pkg_conflict_release(c);
- c = nc;
- }
- free(pkg->conflicts);
- }
+ if (pkg->depends != NULL) pkg_depend_list_finish(pkg->depends);
- if (pkg->depends != NULL) {
- d = TAILQ_FIRST(pkg->depends);
- while (d != NULL) {
- nd = TAILQ_NEXT(d, next);
- pkg_depend_release(d);
- d = nd;
- }
- free(pkg->depends);
- }
+ if (pkg->files != NULL) pkg_file_list_finish(pkg->files);
- if (pkg->files != NULL) {
- f = TAILQ_FIRST(pkg->files);
- while (f != NULL) {
- nf = TAILQ_NEXT(f, next);
- pkg_file_release(f);
- f = nf;
- }
- free(pkg->files);
- }
+ free(pkg);
+}
- free(pkg);
+const char *
+pkg_key(struct pkg *pkg)
+{
+ return (pkg->key);
}
/* Get the origin (fbsd ports) of the package. */
@@ -171,6 +148,11 @@
{
if (pkg->files == NULL)
pkg->read_files(pkg);
+ /*
+ * XXX: These *_list functions should actually return copies of the pkg
+ * internal lists, I think. That or they're going to need to be const
+ * references...
+ */
return (pkg->files);
}
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.h#13 (text+ko) ====
@@ -73,6 +73,12 @@
int pkg_list_finish(struct pkg_list *);
/*
+ * Assuming this is a keyval db, get the key for this package (defaults to the
+ * name of the package.
+ */
+const char *pkg_key(struct pkg *);
+
+/*
* Retrieve the name of a package.
*/
const char *pkg_name(struct pkg *);
@@ -92,6 +98,10 @@
struct pkg_file_list *pkg_files(struct pkg *);
+int pkg_file_finish(struct pkg_file *);
+
+int pkg_file_list_finish(struct pkg_file_list *);
+
struct pkg_file *pkg_add_file(struct pkg *, const char *,
const char *, int);
@@ -101,6 +111,10 @@
struct pkg_depend_list *pkg_depends(struct pkg *);
+int pkg_depend_finish(struct pkg_depend *);
+
+int pkg_depend_list_finish(struct pkg_depend_list *);
+
struct pkg_depend *pkg_add_depend(struct pkg *, const char *,
const char *);
@@ -109,6 +123,10 @@
struct pkg_conflict_list *pkg_conflicts(struct pkg *);
+int pkg_conflict_finish(struct pkg_conflict *);
+
+int pkg_conflict_list_finish(struct pkg_conflict_list *);
+
struct pkg_conflict *pkg_add_conflict(struct pkg *, const char *,
const char *);
==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_types.h#6 (text+ko) ====
==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/pkg_info.c#9 (text+ko) ====
@@ -420,8 +420,8 @@
pkg_name(pkg));
}
}
-
- // pkg_file_list_release(files);
+
+ // pkg_file_list_finish(files);
}
} else if (_c->lookup_origin != NULL) {
if (!_c->quiet)
@@ -468,8 +468,12 @@
}
}
+ /* This will also _finish any lists we have out. Not sure how I feel
+ * about that, because it might be confusing to the client. Look into
+ * copying the lists for the _list functions. */
pkg_list_finish(pkgs);
- pkg_db_finish(db);
+ /* This is a read-only app, so just close. */
+ pkg_db_close(db);
return (r);
}
@@ -553,7 +557,12 @@
struct pkg_file *file;
if (FLAGGED(_c->show_flags, SHOW_INDEX))
- printf("%-19s %s\n", pkg_name(pkg), pkg_comment(pkg));
+ /*
+ * This is a case where we only need the name of this package
+ * and nothing else from the manifest, so let's cheat and use
+ * the key, which is name for fbsd_directorydb.
+ */
+ printf("%-19s %s\n", pkg_key(pkg), pkg_comment(pkg));
else {
if (!_c->quiet)
printf("%sInformation for %s:\n\n", _c->info_prefix,
@@ -580,6 +589,8 @@
"Conflicts %s\n"),
pkg_conflict_expr(conflict));
}
+
+ // pkg_conflict_list_finish(conflicts);
}
if (_c->show_flags & SHOW_DEPEND) {
@@ -595,6 +606,8 @@
"\tdependency origin: %s\n"),
pkg_depend_origin(depend));
}
+
+ // pkg_depend_list_finish(depends);
/* Separator. */
// printf("\n");
}
@@ -675,6 +688,8 @@
printf("%s/%s\n", last_prefix,
pkg_file_pathname(file));
}
+
+ // pkg_file_list_finish(files);
}
if (_c->show_flags & SHOW_SIZE) {}
@@ -699,6 +714,8 @@
pkg_file_prefix(file),
pkg_file_pathname(file));
}
+
+ // pkg_file_list_finish(files);
}
if (_c->show_flags & SHOW_ORIGIN) {
More information about the p4-projects
mailing list