socsvn commit: r253789 - in soc2013/mattbw/backend: . actions
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Mon Jul 1 09:53:06 UTC 2013
Author: mattbw
Date: Mon Jul 1 09:53:06 2013
New Revision: 253789
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253789
Log:
(fixed build, untested) finished rehashing the iterator logic ready for supporting jobs, next step is to merge query relaed code into one file
Modified:
soc2013/mattbw/backend/actions/install-packages.c
soc2013/mattbw/backend/db.c
soc2013/mattbw/backend/db.h
soc2013/mattbw/backend/iterate.c
soc2013/mattbw/backend/iterate.h
Modified: soc2013/mattbw/backend/actions/install-packages.c
==============================================================================
--- soc2013/mattbw/backend/actions/install-packages.c Mon Jul 1 09:02:18 2013 (r253788)
+++ soc2013/mattbw/backend/actions/install-packages.c Mon Jul 1 09:53:06 2013 (r253789)
@@ -51,12 +51,12 @@
jobs = NULL;
err = pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db);
- if (err != E_OK)
+ if (err != EPKG_OK)
pk_backend_error_code(backend,
PK_ERROR_ENUM_INTERNAL_ERROR,
"pkg_jobs_new failed");
else
- err = db_query_to_job(id, backend, db, LOAD_FLAGS, jobs);
+ err = db_query_to_job(id, backend, db, jobs);
/* TODO: actually install */
pk_backend_error_code(backend, PK_ERROR_ENUM_NOT_SUPPORTED, NULL);
Modified: soc2013/mattbw/backend/db.c
==============================================================================
--- soc2013/mattbw/backend/db.c Mon Jul 1 09:02:18 2013 (r253788)
+++ soc2013/mattbw/backend/db.c Mon Jul 1 09:53:06 2013 (r253789)
@@ -43,7 +43,6 @@
PkBackend *backend,
struct pkgdb *db,
int load_flags,
- pkg_func_ptr emitter,
gchar **match_id_p,
struct pkg **match_pkg_p);
@@ -111,25 +110,28 @@
&match_id,
&match_pkg);
if (success == TRUE && match_id != NULL && match_pkg != NULL)
- emitter(pkg, match_id, backend);
+ emitter(match_pkg, match_id, backend);
- pkg_free(pkg);
+ pkg_free(match_pkg);
g_free(match_id);
+
+ return success;
}
/*
* Performs a package database query against a PackageID, and then adds the
* matching results to a pkg job.
- *
+ *
* The round trip through the database seems like a strange idea given that
* pkg_jobs takes a package name. At the moment this is done to ensure that
* the package matches the PackageID fully.
+ *
+ * TODO: do something about the redundancy in both this and the emitter variant.
*/
gboolean
db_query_to_job(const gchar *id,
PkBackend *backend,
struct pkgdb *db,
- int load_flags,
struct pkg_jobs *jobs)
{
gboolean success;
@@ -139,20 +141,21 @@
success = db_query_match(id,
backend,
db,
- load_flags,
+ PKG_LOAD_BASIC,
&match_id,
&match_pkg);
if (success == TRUE && match_id != NULL && match_pkg != NULL) {
- gchar *name[1];
+ gchar *name[1];
name[0] = NULL;
- pkg_get(PKG_NAME, &(name[0]));
-
+ pkg_get(match_pkg, PKG_NAME, &(name[0]));
+
pkg_jobs_add(jobs, MATCH_EXACT, name, 1);
}
-
- pkg_free(pkg);
+ pkg_free(match_pkg);
g_free(match_id);
+
+ return success;
}
/*
@@ -166,7 +169,6 @@
PkBackend *backend,
struct pkgdb *db,
int load_flags,
- pkg_func_ptr emitter,
gchar **match_id_p,
struct pkg **match_pkg_p)
{
@@ -243,7 +245,8 @@
PkBackend *backend,
struct pkgdb *db,
int load_flags,
- pkg_func_ptr emitter)
+ gchar **match_id_p,
+ struct pkg **match_pkg_p)
{
struct pkgdb_it *it;
gboolean success;
@@ -267,13 +270,14 @@
if (it != NULL)
- success = iterate_id_matches(it,
- backend,
- name,
- version,
- arch,
- reponame,
- load_flags,
- emitter);
+ success = match_id_in_it(it,
+ backend,
+ name,
+ version,
+ arch,
+ reponame,
+ load_flags,
+ match_id_p,
+ match_pkg_p);
return success;
}
Modified: soc2013/mattbw/backend/db.h
==============================================================================
--- soc2013/mattbw/backend/db.h Mon Jul 1 09:02:18 2013 (r253788)
+++ soc2013/mattbw/backend/db.h Mon Jul 1 09:53:06 2013 (r253789)
@@ -35,5 +35,10 @@
struct pkgdb *db,
int load_flags,
pkg_func_ptr emitter);
+gboolean
+db_query_to_job(const gchar *id,
+ PkBackend *backend,
+ struct pkgdb *db,
+ struct pkg_jobs *jobs);
#endif /* !_PKGNG_BACKEND_DETAILS_H_ */
Modified: soc2013/mattbw/backend/iterate.c
==============================================================================
--- soc2013/mattbw/backend/iterate.c Mon Jul 1 09:02:18 2013 (r253788)
+++ soc2013/mattbw/backend/iterate.c Mon Jul 1 09:53:06 2013 (r253789)
@@ -37,52 +37,48 @@
gboolean
-iterate_id_matches(struct pkgdb_it *iterator,
- PkBackend *backend,
- const char *name,
- const char *version,
- const char *arch,
- const char *data,
- int fetch_flags,
- pkg_func_ptr iterate_f)
+match_id_in_it(struct pkgdb_it *iterator,
+ PkBackend *backend,
+ const char *name,
+ const char *version,
+ const char *arch,
+ const char *data,
+ int load_flags,
+ gchar **match_id_p,
+ struct pkg **match_pkg_p)
{
/* TODO: Filters */
gboolean found;
int err;
- struct pkg *pkg;
- gchar *match_id;
found = FALSE;
- pkg = NULL;
- match_id = NULL;
+ *match_pkg_p = NULL;
+ *match_id_p = NULL;
/*
* Stop pkg from catching fire if we try to load files from
* non-installed packages.
*/
- if ((fetch_flags & PKG_LOAD_FILES) && g_strcmp0(data,
- "installed") != 0) {
+ if ((load_flags & PKG_LOAD_FILES) && g_strcmp0(data,
+ "installed") != 0) {
pk_backend_error_code(backend,
PK_ERROR_ENUM_CANNOT_GET_FILELIST,
"Cannot get files for non-installed package."
);
err = EPKG_FATAL;
} else {
- for (HASH_FOR(err, pkgdb_it_next, iterator, &pkg, fetch_flags)) {
- if (try_id_match(pkg,
+ for (HASH_FOR(err, pkgdb_it_next, iterator, match_pkg_p, load_flags)) {
+ if (try_id_match(*match_pkg_p,
name,
version,
arch,
data,
- &match_id) == TRUE) {
+ match_id_p) == TRUE) {
found = TRUE;
- iterate_f(pkg, match_id, backend);
+ break;
}
- if (match_id != NULL)
- g_free(match_id);
}
}
- pkg_free(pkg);
return found;
}
Modified: soc2013/mattbw/backend/iterate.h
==============================================================================
--- soc2013/mattbw/backend/iterate.h Mon Jul 1 09:02:18 2013 (r253788)
+++ soc2013/mattbw/backend/iterate.h Mon Jul 1 09:53:06 2013 (r253789)
@@ -31,14 +31,15 @@
typedef gboolean (*ids_func_ptr) (const gchar *id, PkBackend *backend, struct pkgdb *db);
gboolean
-iterate_id_matches(struct pkgdb_it *iterator,
- PkBackend *backend,
- const gchar *name,
- const gchar *version,
- const gchar *arch,
- const gchar *data,
- int fetch_flags,
- pkg_func_ptr iterate_f);
+match_id_in_it(struct pkgdb_it *iterator,
+ PkBackend *backend,
+ const gchar *name,
+ const gchar *version,
+ const gchar *arch,
+ const gchar *data,
+ int load_flags,
+ gchar **match_id_p,
+ struct pkg **match_pkg_p);
gboolean iterate_ids(PkBackend *backend, ids_func_ptr iterate_f);
#endif /* !_PKGNG_BACKEND_ITERATE_H_ */
More information about the svn-soc-all
mailing list