socsvn commit: r253547 - in soc2013/mattbw/backend: . actions
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Wed Jun 26 16:51:45 UTC 2013
Author: mattbw
Date: Wed Jun 26 16:51:45 2013
New Revision: 253547
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253547
Log:
generic pkg iterator traversal macro
Added:
soc2013/mattbw/backend/hash_traverse.h
Modified:
soc2013/mattbw/backend/actions/get-repo-list.c
soc2013/mattbw/backend/iterate.c
Modified: soc2013/mattbw/backend/actions/get-repo-list.c
==============================================================================
--- soc2013/mattbw/backend/actions/get-repo-list.c Wed Jun 26 16:31:13 2013 (r253546)
+++ soc2013/mattbw/backend/actions/get-repo-list.c Wed Jun 26 16:51:45 2013 (r253547)
@@ -1,5 +1,4 @@
/*-
- *
* Copyright (C) 2013 Matt Windsor <mattbw at FreeBSD.org>
*
* Licensed under the GNU General Public License Version 2
@@ -23,6 +22,8 @@
#include "../pk-backend.h"
#include "pkg.h"
+#include "../hash_traverse.h" /* HASH_FOR */
+
/*
* The thread that performs a GetRepoList operation. Should be invoked by the
* pk_backend_get_repo_list hook.
@@ -30,23 +31,16 @@
gboolean
get_repo_list_thread(PkBackend *backend)
{
- int err;
+ int err;
struct pkg_repo *repo;
-
+
repo = NULL;
- for (;;) {
- err = pkg_repos(&repo);
- if (err == EPKG_OK && repo != NULL)
- pk_backend_repo_detail(backend,
-pkg_repo_ident(repo),
-pkg_repo_name(repo),
-pkg_repo_enabled(repo));
- else
- break;
- }
+ for (HASH_FOR(err, pkg_repos, &repo))
+ pk_backend_repo_detail(backend,
+ pkg_repo_ident(repo),
+ pkg_repo_name(repo),
+ pkg_repo_enabled(repo));
return (err == EPKG_END ? TRUE : FALSE);
}
-
-
Added: soc2013/mattbw/backend/hash_traverse.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/hash_traverse.h Wed Jun 26 16:51:45 2013 (r253547)
@@ -0,0 +1,27 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at FreeBSD.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _PKGNG_BACKEND_HASH_TRAVERSE_H_
+#define _PKGNG_BACKEND_HASH_TRAVERSE_H_
+
+#define HASH_FOR(err, hash, ...) \
+ (err) = hash(__VA_ARGS__); (err) == EPKG_OK; (err) = hash(__VA_ARGS__)
+
+#endif /* !_PKGNG_BACKEND_HASH_TRAVERSE_H_ */
Modified: soc2013/mattbw/backend/iterate.c
==============================================================================
--- soc2013/mattbw/backend/iterate.c Wed Jun 26 16:31:13 2013 (r253546)
+++ soc2013/mattbw/backend/iterate.c Wed Jun 26 16:51:45 2013 (r253547)
@@ -26,6 +26,7 @@
#include "iterate.h" /* Prototypes */
#include "db.h" /* open_remote_db */
+#include "hash_traverse.h" /* HASH_FOR */
static gboolean
try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const
@@ -52,33 +53,33 @@
found = FALSE;
pkg = NULL;
match_id = NULL;
- do {
- /*
- * Stop pkg from catching fire if we try to load files from
- * non-installed packages.
- */
- if ((fetch_flags & PKG_LOAD_FILES) && g_strcmp0(data,
+
+ /*
+ * 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) {
- pk_backend_error_code(backend,
- PK_ERROR_ENUM_CANNOT_GET_FILELIST,
+ pk_backend_error_code(backend,
+ PK_ERROR_ENUM_CANNOT_GET_FILELIST,
"Cannot get files for non-installed package."
);
- err = EPKG_FATAL;
- } else
- err = pkgdb_it_next(iterator, &pkg, fetch_flags);
-
- if (err == EPKG_OK && try_id_match(pkg,
- name,
- version,
- arch,
- data,
- &match_id) == TRUE) {
- found = TRUE;
- iterate_f(pkg, match_id, backend);
+ err = EPKG_FATAL;
+ } else {
+ for (HASH_FOR(err, pkgdb_it_next, iterator, &pkg, fetch_flags)) {
+ if (err == EPKG_OK && try_id_match(pkg,
+ name,
+ version,
+ arch,
+ data,
+ &match_id) == TRUE) {
+ found = TRUE;
+ iterate_f(pkg, match_id, backend);
+ }
+ if (match_id != NULL)
+ g_free(match_id);
}
- if (match_id != NULL)
- g_free(match_id);
- } while (err == EPKG_OK && found == FALSE);
+ }
pkg_free(pkg);
return found;
More information about the svn-soc-all
mailing list