From owner-svn-soc-all@FreeBSD.ORG Thu Jul 18 17:43:53 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id B89AF6AC for ; Thu, 18 Jul 2013 17:43:53 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 9B69ED0B for ; Thu, 18 Jul 2013 17:43:53 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r6IHhr9i082890 for ; Thu, 18 Jul 2013 17:43:53 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r6IHhr9u082885 for svn-soc-all@FreeBSD.org; Thu, 18 Jul 2013 17:43:53 GMT (envelope-from mattbw@FreeBSD.org) Date: Thu, 18 Jul 2013 17:43:53 GMT Message-Id: <201307181743.r6IHhr9u082885@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254923 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jul 2013 17:43:53 -0000 Author: mattbw Date: Thu Jul 18 17:43:53 2013 New Revision: 254923 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254923 Log: implement SearchFiles, rudimentary testing at the moment Added: soc2013/mattbw/backend/actions/search_files.c Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/actions.h soc2013/mattbw/backend/pk-backend-pkgng.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Thu Jul 18 17:01:02 2013 (r254922) +++ soc2013/mattbw/backend/Makefile Thu Jul 18 17:43:53 2013 (r254923) @@ -21,6 +21,7 @@ actions/refresh_cache.c \ actions/remove_packages.c \ actions/resolve.c \ + actions/search_files.c \ actions/search_groups.c \ actions/search_names.c Modified: soc2013/mattbw/backend/actions.h ============================================================================== --- soc2013/mattbw/backend/actions.h Thu Jul 18 17:01:02 2013 (r254922) +++ soc2013/mattbw/backend/actions.h Thu Jul 18 17:43:53 2013 (r254923) @@ -36,6 +36,7 @@ gboolean refresh_cache_thread(PkBackend *backend); gboolean remove_packages_thread(PkBackend *backend); gboolean resolve_thread(PkBackend *backend); +gboolean search_files_thread(PkBackend *backend); gboolean search_groups_thread(PkBackend *backend); gboolean search_names_thread(PkBackend *backend); gboolean simulate_install_files_thread(PkBackend *backend); Added: soc2013/mattbw/backend/actions/search_files.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/actions/search_files.c Thu Jul 18 17:43:53 2013 (r254923) @@ -0,0 +1,101 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * 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. + */ + +#include /* assert */ +#include /* bool, TRUE, FALSE */ +#include "../pk-backend.h" +#include "pkg.h" + +#include "../actions.h" /* search_files_thread prototype */ +#include "../db.h" /* db_open_remote */ +#include "../utils.h" /* INTENTIONALLY_IGNORE */ +#include "../pkgutils.h" /* pkgutils_... */ + +/* + * Searches for packages containing specified files. + */ +gboolean +search_files_thread(PkBackend *backend) +{ + bool at_least_one; + gboolean success; + guint filec; + guint i; + struct pkg *pkg; + struct pkgdb *db; + struct pkgdb_it *it; + gchar **filev; + + assert(backend != NULL); + db = NULL; + it = NULL; + pkg = NULL; + success = FALSE; + + (void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); + (void)pk_backend_set_percentage(backend, 0); + + db = db_open_remote(backend); + if (db == NULL) + goto cleanup; + + filev = pk_backend_get_strv(backend, "search"); + if (filev == NULL) { + ERR(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "search is NULL"); + goto cleanup; + } + filec = g_strv_length(filev); + if (filec == 0) { + ERR(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "no files given"); + goto cleanup; + } + + for (i = 0; i < filec; i++) { + at_least_one = false; + + it = pkgdb_query_which(db, filev[i], false); + if (it != NULL) { + while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) + == EPKG_OK) { + pkgutils_emit(pkg, backend, + pkgutils_pkg_current_state(pkg)); + at_least_one = true; + } + } + + /* TODO: specifically name file? */ + if (at_least_one == false) + ERR(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, + "no matches for file"); + + (void)pk_backend_set_percentage(backend, + ((i + 1) * 100) / filec); + } + + success = TRUE; + +cleanup: + pkg_free(pkg); + pkgdb_it_free(it); + pkgdb_close(db); + + (void)pk_backend_finished(backend); + return success; +} Modified: soc2013/mattbw/backend/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/backend/pk-backend-pkgng.c Thu Jul 18 17:01:02 2013 (r254922) +++ soc2013/mattbw/backend/pk-backend-pkgng.c Thu Jul 18 17:43:53 2013 (r254923) @@ -194,6 +194,15 @@ } void +pk_backend_search_files(PkBackend *backend, PkBitfield filters, gchar **search) +{ + + INTENTIONALLY_IGNORE(filters); /* retrieved from backend */ + INTENTIONALLY_IGNORE(search); /* retrieved from backend */ + THREAD(backend, search_files_thread); +} + +void pk_backend_search_groups(PkBackend *backend, PkBitfield filters, gchar **values) {