Date: Mon, 24 Jun 2013 23:00:06 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253458 - soc2013/mattbw/backend Message-ID: <201306242300.r5ON068D084963@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mattbw Date: Mon Jun 24 23:00:06 2013 New Revision: 253458 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253458 Log: unify get_remote_details and get_local_details Modified: soc2013/mattbw/backend/get-details.c Modified: soc2013/mattbw/backend/get-details.c ============================================================================== --- soc2013/mattbw/backend/get-details.c Mon Jun 24 22:15:36 2013 (r253457) +++ soc2013/mattbw/backend/get-details.c Mon Jun 24 23:00:06 2013 (r253458) @@ -31,19 +31,13 @@ /* TODO: move out of get-details? */ gboolean string_match(const char *left, const char *right); static gboolean -get_local_details(const gchar *name, +get_details_query(const gchar *name, const gchar *version, const gchar *arch, + const gchar *reponame, PkBackend *backend, struct pkgdb *db); static gboolean -get_remote_details(const gchar *name, - const gchar *version, - const gchar *arch, - const gchar *reponame, - PkBackend *backend, - struct pkgdb *db); -static gboolean get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db); @@ -160,11 +154,19 @@ return found; } -/* Looks the split PackageID up in the local database. */ +/* + * Looks the split PackageID up in the package databases. + * + * Usually, a remote query will be done on the repository named by "reponame". + * If reponame is NULL, a remote check will be done against all repostories. + * If it is "installed", a local check will be done. (This is in keeping + * with the special meaning of the "installed" repository in PackageIDs). + */ static gboolean -get_local_details(const gchar *name, +get_details_query(const gchar *name, const gchar *version, const gchar *arch, + const gchar *reponame, PkBackend *backend, struct pkgdb *db) { @@ -172,31 +174,12 @@ gboolean success; success = FALSE; - it = pkgdb_query(db, name, MATCH_EXACT); - if (it) - success = get_details_check_matches(it, - name, - version, - arch, - "installed", - backend); - return success; -} -/* Looks the split PackageID up in the remote database. */ -gboolean -get_remote_details(const gchar *name, - const gchar *version, - const gchar *arch, - const gchar *reponame, - PkBackend *backend, - struct pkgdb *db) -{ - struct pkgdb_it *it; - gboolean success; - - success = FALSE; - it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); + /* Are we doing a local query? */ + if (g_strcmp0(reponame, "installed") == 0) + it = pkgdb_query(db, name, MATCH_EXACT); + else + it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); if (it) success = get_details_check_matches(it, name, @@ -246,22 +229,27 @@ /* - * If the PackageID is for an installed package, do a local - * query. If it is for a specific repo, do a remote query on - * it. And if the PackageID has no repository information at - * all, check both local and repo-generic remote. (TODO: - * local packages?) + * If the PackageID has a repository specified (even if it's + * "installed" i.e. currently installed package), running + * "get_details_query" directly should handle remote/local + * queries properly. + * + * If there is no repository specified, however (data is NULL), + * we may need to check both the local and (all) remote + * repositories, in that order. (TODO: local packages?) */ - if (g_strcmp0(data, "installed") == 0) - success = get_local_details(name, version, arch, backend, db); - else if (data != NULL) /* FIXME: treats 'local' as repo */ - success = get_remote_details(name, version, arch, data, backend, db); - else { - /* TODO: ensure this is correct behaviour */ - success = get_local_details(name, version, arch, backend, db); + if (data == NULL) { + /* Try local database first. */ + success = get_details_query(name, + version, + arch, + "installed", + backend, + db); if (success == FALSE) - success = get_remote_details(name, version, arch, data, backend, db); - } + success = get_details_query(name, version, NULL, data, backend, db); + } else + success = get_details_query(name, version, arch, data, backend, db); /* * Assume any error is due to not finding packages. At time * of writing this is true, but may change.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306242300.r5ON068D084963>