socsvn commit: r253322 - soc2013/mattbw/dummy
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Fri Jun 21 18:04:38 UTC 2013
Author: mattbw
Date: Fri Jun 21 18:04:37 2013
New Revision: 253322
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253322
Log:
some indent-ing, added flatsize, have not compiled yet, may not work. Will fix up later
Added:
soc2013/mattbw/dummy/.indent.pro
Modified:
soc2013/mattbw/dummy/get-details.c
Added: soc2013/mattbw/dummy/.indent.pro
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/dummy/.indent.pro Fri Jun 21 18:04:37 2013 (r253322)
@@ -0,0 +1,3 @@
+-TPkBackend
+-Tgchar
+-Tgboolean
Modified: soc2013/mattbw/dummy/get-details.c
==============================================================================
--- soc2013/mattbw/dummy/get-details.c Fri Jun 21 17:36:33 2013 (r253321)
+++ soc2013/mattbw/dummy/get-details.c Fri Jun 21 18:04:37 2013 (r253322)
@@ -24,36 +24,65 @@
#include "pk-backend.h"
#include "pkg.h"
+/*
+ * Checks two strings with strcmp and emits TRUE if they match. If either
+ * string is NULL, emit TRUE as well (this is so that missing PackageID
+ * elements trigger matches).
+ */
gboolean
-get_details_check_matches(struct pkgdb_it *matches, gchar *id_name, gchar *id_version, gchar *id_arch, gchar *id_data, PkBackend *backend)
+string_match(const char *left, const char *right)
+{
+ int result;
+
+ if (left == NULL || right == NULL)
+ result = TRUE;
+ else
+ result = (strcmp(left, right) == 0 ? TRUE : FALSE);
+
+ return result;
+}
+
+/*
+ * Go through a database iterator of possible package matches and emit any
+ * that match the split PackageID.
+ */
+gboolean
+get_details_check_matches(struct pkgdb_it *matches,
+ gchar *id_name,
+ gchar *id_version,
+ gchar *id_arch,
+ gchar *id_data,
+ PkBackend *backend)
{
gboolean found;
int err;
- struct pkg *match;
+ struct pkg *match;
found = FALSE;
match = NULL;
do {
err = pkgdb_it_next(matches, &match, PKG_LOAD_BASIC);
if (err == EPKG_OK) {
- const char *name;
- const char *version;
- const char *description;
- const char *arch;
- const char *reponame;
- const char *data;
- const char *www;
- pkg_t type;
+ const char *arch;
+ const char *data;
+ const char *description;
+ const char *name;
+ const char *reponame;
+ const char *version;
+ const char *www;
+ pkg_t type;
+ int64_t flatsize;
pkg_get(match,
- PKG_NAME, &name,
- PKG_VERSION, &version,
- PKG_DESC, &description,
- PKG_ARCH, &arch,
- PKG_REPONAME, &reponame,
- PKG_WWW, &www);
+ PKG_ARCH, &arch,
+ PKG_DESC, &description,
+ PKG_NAME, &name,
+ PKG_REPONAME, &reponame,
+ PKG_VERSION, &version,
+ PKG_WWW, &www,
+ PKG_FLATSIZE, &size);
- switch(pkg_type(match)) {
+ switch (pkg_type(match)) {
case PKG_FILE:
data = "local";
break;
@@ -65,24 +94,29 @@
break;
}
- if ((id_name == NULL || g_strcmp0(name, id_name) == 0) &&
- (id_version == NULL || g_strcmp0(version, id_version) == 0) &&
- (id_arch == NULL || g_strcmp0(arch, id_arch) == 0) &&
- (id_data == NULL || g_strcmp0(data, id_data) == 0)) {
- gchar *new_id;
+ /*
+ * Emit if this package's PackageID fields match the
+ * original PackageID. Of course, the original ID
+ * might have missing fields (NULLs), so we treat a
+ * comparison involving one as a success.
+ */
+ if (string_match(name, id_name) &&
+ string_match(version, id_version) &&
+ string_match(arch, id_arch) &&
+ string_match(data, id_data)) {
+ gchar *new_id;
found = TRUE;
new_id = pk_package_id_build(name, version, arch, data);
/* TODO: implement category, size and licence */
pk_backend_details(backend,
- new_id,
- NULL,
- PK_GROUP_ENUM_PROGRAMMING,
- description,
- www,
- 0
- );
+ new_id,
+ NULL,
+ PK_GROUP_ENUM_PROGRAMMING,
+ description,
+ www,
+ flatsize);
g_free(new_id);
}
@@ -92,12 +126,13 @@
return found;
}
+/* Looks the split PackageID up in the local database. */
gboolean
get_local_details(gchar *name,
- gchar *version,
- gchar *arch,
- PkBackend *backend,
- struct pkgdb *db)
+ gchar *version,
+ gchar *arch,
+ PkBackend *backend,
+ struct pkgdb *db)
{
struct pkgdb_it *it;
gboolean success;
@@ -106,22 +141,23 @@
it = pkgdb_query(db, name, MATCH_EXACT);
if (it)
success = get_details_check_matches(
- it,
- name,
- version,
- arch,
- "installed",
- backend);
+ it,
+ name,
+ version,
+ arch,
+ "installed",
+ backend);
return success;
}
+/* Looks the split PackageID up in the remote database. */
gboolean
get_remote_details(gchar *name,
- gchar *version,
- gchar *arch,
- gchar *reponame,
- PkBackend *backend,
- struct pkgdb *db)
+ gchar *version,
+ gchar *arch,
+ gchar *reponame,
+ PkBackend *backend,
+ struct pkgdb *db)
{
struct pkgdb_it *it;
gboolean success;
@@ -130,35 +166,35 @@
it = pkgdb_rquery(db, name, MATCH_EXACT, reponame);
if (it)
success = get_details_check_matches(
- it,
- name,
- version,
- arch,
- reponame,
- backend);
+ it,
+ name,
+ version,
+ arch,
+ reponame,
+ backend);
return success;
}
gboolean
get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db)
{
- gchar **parts;
+ gchar **parts;
gboolean success;
success = FALSE;
parts = pk_package_id_split(package_id);
- if (parts == NULL)
+ if (parts == NULL)
pk_backend_error_code(backend,
- PK_ERROR_ENUM_PACKAGE_ID_INVALID,
- "invalid package id");
+ PK_ERROR_ENUM_PACKAGE_ID_INVALID,
+ "invalid package id");
else {
struct pkgdb_it *packages;
/* Parts of the package ID */
- gchar *name;
- gchar *version;
- gchar *arch;
- gchar *data;
+ gchar *name;
+ gchar *version;
+ gchar *arch;
+ gchar *data;
name = parts[PK_PACKAGE_ID_NAME];
if (name != NULL && strlen(name) == 0)
@@ -178,15 +214,16 @@
- /* 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 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 (g_strcmp0(data, "installed") == 0)
success = get_local_details(name, version, arch, backend, db);
- else if (data != NULL) /* FIXME: treats 'local' as repo */
+ 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 */
@@ -194,15 +231,16 @@
if (success == FALSE)
success = get_remote_details(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.
+ /*
+ * Assume any error is due to not finding packages. At time
+ * of writing this is true, but may change.
*/
if (success == FALSE)
pk_backend_error_code(backend,
- PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
- "package not found");
+ PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
+ "package not found");
g_strfreev(parts);
}
-
+
return success;
}
More information about the svn-soc-all
mailing list