Date: Wed, 28 Aug 2013 18:39:25 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256666 - in soc2013/mattbw/backend: . jobs query Message-ID: <201308281839.r7SIdPjf055158@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mattbw Date: Wed Aug 28 18:39:24 2013 New Revision: 256666 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256666 Log: Fix the failing unit test (but not Resolve). There seems to be some sort of memory corruption coming off Resolve; the packagekitd log showed a broken PackageID with a malformed repo spewing non-ASCII characters. Added: soc2013/mattbw/backend/namever.c soc2013/mattbw/backend/namever.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/jobs/check.c soc2013/mattbw/backend/pkgutils.c soc2013/mattbw/backend/pkgutils.h soc2013/mattbw/backend/query.h soc2013/mattbw/backend/query/check.c soc2013/mattbw/backend/utils.c soc2013/mattbw/backend/utils.h Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Wed Aug 28 17:58:30 2013 (r256665) +++ soc2013/mattbw/backend/Makefile Wed Aug 28 18:39:24 2013 (r256666) @@ -29,6 +29,7 @@ group_map.c \ jobs.c \ licenses.c \ + namever.c \ pkgutils.c \ search.c \ utils.c @@ -51,6 +52,7 @@ actions/update_system.c SRCS+= \ + query/check.c \ query/depends.c \ query/do.c \ query/find.c \ @@ -67,8 +69,9 @@ PKGS= pkg gio-2.0 gio-unix-2.0 # ATF test flags -TESTSRCS= \ - query/id_test.c +TESTPROGS= \ + query/id_test \ + query/check_test \ TESTCFLAGS= `pkgconf --cflags atf-c` TESTLDFLAGS= `pkgconf --libs-only-L --libs-only-other atf-c` @@ -76,13 +79,13 @@ # 0.6.* versions of PackageKit do not export pkgconf information, so here's a # bodge. -USE_PK_PKGCONF= 0 # Set to 1 if using recent PackageKit -.if USE_PK_PKGCONF -PKGS+= packagekit-glib2 -.else +#USE_PK_PKGCONF= 0 # Set to 1 if using recent PackageKit +#.if USE_PK_PKGCONF +#PKGS+= packagekit-glib2 +#.else CFLAGS+= -I/usr/local/include/PackageKit -I/usr/local/include/PackageKit/backend LDFLAGS+= -L/usr/local/lib -lpackagekit-glib2 -.endif +#.endif CFLAGS+= `pkg-config --cflags ${PKGS}` CFLAGS+= -DPK_COMPILATION @@ -92,11 +95,20 @@ group_map.c: groups group_map.awk sort groups | awk -f group_map.awk > group_map.c +tests: ${TESTPROGS} + # TODO: Find a more BSD way of doing this -query/id_test: query/id_test.o query/id.o +query/id_test: query/id_test.o query/id.o namever.o ${CC} ${LDFLAGS} ${TESTLDFLAGS} -o ${.TARGET} ${.ALLSRC} ${LIBS} ${TESTLIBS} query/id_test.o: query/id_test.c - ${CC} ${CFLAGS} ${TESTCFLAGS} -o query/id_test.o -c query/id_test.c + ${CC} ${CFLAGS} ${TESTCFLAGS} -o ${.TARGET} -c ${.ALLSRC} + +query/check_test: query/check_test.o query/check.o query/id.o query/packages.o query/find.o namever.o + ${CC} ${LDFLAGS} ${TESTLDFLAGS} -o ${.TARGET} ${.ALLSRC} ${LIBS} ${TESTLIBS} + +query/check_test.o: query/check_test.c + ${CC} ${CFLAGS} ${TESTCFLAGS} -o ${.TARGET} -c ${.ALLSRC} + .include <bsd.lib.mk> Modified: soc2013/mattbw/backend/jobs/check.c ============================================================================== --- soc2013/mattbw/backend/jobs/check.c Wed Aug 28 17:58:30 2013 (r256665) +++ soc2013/mattbw/backend/jobs/check.c Wed Aug 28 18:39:24 2013 (r256666) @@ -27,6 +27,7 @@ #include "../pk-backend.h" /* pk_..., Pk... */ #include "pkg.h" /* pkg_... */ +#include "../namever.h" /* namever_... */ #include "../utils.h" /* ERR */ #include "../pkgutils.h" /* pkgutils_... */ #include "../query.h" /* query_... */ @@ -78,7 +79,7 @@ /* Does this package's name and version match a PackageID? */ if (strcmp(namever, query_id->namever) == 0) { /* Does the rest of the PackageID match up? */ - success = query_match_pkg_to_id(pkg, query_id); + success = query_check_package(pkg, query_id); } return success; @@ -93,17 +94,17 @@ guint i; int err; char *namever; - struct pkg *pkg; + struct pkg *package; assert(jobs != NULL); assert(query_ids != NULL); assert(0 < count); - pkg = NULL; + package = NULL; success = true; while (success) { - err = pkg_jobs(jobs, &pkg); + err = pkg_jobs(jobs, &package); if (err != EPKG_OK) { /* Did we reach the end of the job iterator? */ if (err != EPKG_END) { @@ -112,9 +113,9 @@ break; } - assert(pkg != NULL); + assert(package != NULL); - namever = pkgutils_pkg_namever(pkg); + namever = namever_from_package(package); if (namever == NULL) { success = false; } @@ -126,11 +127,12 @@ } assert(success); - success = jobs_check_id_on_package(pkg, query_ids + i, + success = jobs_check_id_on_package(package, + query_ids + i, namever); if (success && reject_non_updates && - pkgutils_pkg_install_state(pkg) != + pkgutils_pkg_install_state(package) != PK_INFO_ENUM_UPDATING) { success = false; } Added: soc2013/mattbw/backend/namever.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/namever.c Wed Aug 28 18:39:24 2013 (r256666) @@ -0,0 +1,66 @@ +/*- + * Copyright (C) 2013 Matt Windsor <mattbw@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. + */ + +#include <assert.h> /* assert */ +#include <stdio.h> /* asprintf */ +#include "pkg.h" /* pkg_... */ + +#include "namever.h" /* namever_... */ + +/* + * Functions for dealing with "namevers" (name-version strings). + * + * This file CANNOT depend on PackageKit. + */ + +/* + * Joins a name and a version to form a namever. + * + * To be freed using free(3). Result may be NULL. + */ +char * +namever_from_name_and_version(const char *name, const char *version) +{ + char *result; + + assert(name != NULL); + assert(version != NULL); + + (void)asprintf(&result, "%s-%s", name, version); + return result; +} + +/* + * Allocates and returns a string of the form "name-version" that identifies + * the given package's name and version. + * + * To be freed using free(3). Result may be NULL. + */ +char * +namever_from_package(struct pkg *package) +{ + char *result; + + assert(package != NULL); + + result = NULL; + (void)pkg_asprintf(&result, "%n-%v", package, package); + return result; +} Added: soc2013/mattbw/backend/namever.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/namever.h Wed Aug 28 18:39:24 2013 (r256666) @@ -0,0 +1,27 @@ +/*- + * Copyright (C) 2013 Matt Windsor <mattbw@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_NAMEVER_H_ +#define _PKGNG_BACKEND_NAMEVER_H_ + +char *namever_from_name_and_version(const char *name, const char *version); +char *namever_from_package(struct pkg *package); + +#endif /* !_PKGNG_BACKEND_NAMEVER_H_ */ Modified: soc2013/mattbw/backend/pkgutils.c ============================================================================== --- soc2013/mattbw/backend/pkgutils.c Wed Aug 28 17:58:30 2013 (r256665) +++ soc2013/mattbw/backend/pkgutils.c Wed Aug 28 18:39:24 2013 (r256666) @@ -24,12 +24,15 @@ #include "pk-backend.h" #include "pkg.h" +#include "namever.h" /* namever_... */ #include "pkgutils.h" /* Prototypes */ #include "utils.h" /* INTENTIONALLY_IGNORE */ static bool pkg_matches_filters(struct pkg *pkg, PkBitfield filters); static const char *repo_of_remote(struct pkg *pkg); +/* Package utility functions that do not depend on PackageKit. */ + /* * Infers the correct PkInfoEnum to emit for this package for its current state. */ @@ -118,31 +121,14 @@ id_splits = pk_package_id_split(package_id); assert(id_splits != NULL); - result = NULL; - asprintf(&result, "%s-%s", id_splits[PK_PACKAGE_ID_NAME], + result = namever_from_name_and_version(id_splits[PK_PACKAGE_ID_NAME], id_splits[PK_PACKAGE_ID_VERSION]); g_strfreev(id_splits); return result; } -/* - * Allocates and returns a string of the form "name-version" that identifies - * the given package's name and version. - * - * To be freed using free(3). - */ -char * -pkgutils_pkg_namever(struct pkg *pkg) -{ - char *result; - - assert(pkg != NULL); - result = NULL; - (void)pkg_asprintf(&result, "%n-%v", pkg, pkg); - return result; -} /* * Gets the PackageKit repository name for the package. Modified: soc2013/mattbw/backend/pkgutils.h ============================================================================== --- soc2013/mattbw/backend/pkgutils.h Wed Aug 28 17:58:30 2013 (r256665) +++ soc2013/mattbw/backend/pkgutils.h Wed Aug 28 18:39:24 2013 (r256666) @@ -29,7 +29,6 @@ PkInfoEnum pkgutils_pkg_install_state(struct pkg *pkg); PkInfoEnum pkgutils_pkg_remove_state(struct pkg *pkg); char *pkgutils_package_id_namever(gchar *package_id); -char *pkgutils_pkg_namever(struct pkg *pkg); const char *pkgutils_pk_repo_of(struct pkg *pkg); gchar *pkgutils_pkg_to_id(struct pkg *pkg); void pkgutils_add_old_version(struct pkgdb *db, struct pkg *pkg, struct pkg **old_p); Modified: soc2013/mattbw/backend/query.h ============================================================================== --- soc2013/mattbw/backend/query.h Wed Aug 28 17:58:30 2013 (r256665) +++ soc2013/mattbw/backend/query.h Wed Aug 28 18:39:24 2013 (r256666) @@ -23,6 +23,7 @@ /* Meta-header for the public interfaces to the query system. */ +#include "query/check.h" /* query_check_... */ #include "query/depends.h" /* query_depends_... */ #include "query/do.h" /* query_do_... */ #include "query/match.h" /* query_match_... */ Modified: soc2013/mattbw/backend/query/check.c ============================================================================== --- soc2013/mattbw/backend/query/check.c Wed Aug 28 17:58:30 2013 (r256665) +++ soc2013/mattbw/backend/query/check.c Wed Aug 28 18:39:24 2013 (r256666) @@ -41,6 +41,7 @@ bool matches; char *namever; const char *arch; + const char *name; const char *repo; assert(package != NULL); @@ -49,20 +50,36 @@ namever = namever_from_package(package); - (void)pkg_get(package, PKG_ARCH, &arch, PKG_REPONAME, &repo); + (void)pkg_get(package, + PKG_ARCH, &arch, + PKG_NAME, &name, + PKG_REPONAME, &repo); /* Be cautious and reject matches if the package fields aren't here. */ if (namever == NULL || arch == NULL || repo == NULL) { matches = false; } else { bool namever_matches; + bool namever_matches_name; + bool namever_matches_namever; bool arch_matches; bool repo_matches; - namever_matches = string_match(query_id->namever, namever); + /* + * Allow raw names to match the Query ID namever, as well as + * the full package namevers. + * This allows Resolve to work properly. + */ + namever_matches_name = string_match(query_id->namever, name); + namever_matches_namever = string_match(query_id->namever, + namever); + namever_matches = (namever_matches_name || + namever_matches_namever); + arch_matches = string_match(query_id->arch, arch); repo_matches = string_match(query_id->repo, repo); + matches = (namever_matches && arch_matches && repo_matches); } Modified: soc2013/mattbw/backend/utils.c ============================================================================== --- soc2013/mattbw/backend/utils.c Wed Aug 28 17:58:30 2013 (r256665) +++ soc2013/mattbw/backend/utils.c Wed Aug 28 18:39:24 2013 (r256666) @@ -30,26 +30,6 @@ #include "utils.h" /* prototypes */ /* - * Checks two strings with strcmp and emits TRUE if they match. If either - * string is NULL or empty, emit TRUE as well (this is so that missing - * PackageID elements trigger matches). - */ -bool -string_match(const char *left, const char *right) -{ - bool result; - - if (left == NULL || right == NULL) - result = true; - else if (*left == '\0' || *right == '\0') - result = true; - else - result = (strcmp(left, right) == 0); - - return result; -} - -/* * Finds the type of the given PackageKit repository name. */ enum repo_type Modified: soc2013/mattbw/backend/utils.h ============================================================================== --- soc2013/mattbw/backend/utils.h Wed Aug 28 17:58:30 2013 (r256665) +++ soc2013/mattbw/backend/utils.h Wed Aug 28 18:39:24 2013 (r256666) @@ -38,7 +38,6 @@ #define ERR(backend, type, msg) \ (void)pk_backend_error_code((backend), (type), (msg)) -bool string_match(const char *left, const char *right); enum repo_type type_of_repo_name(const char *name); gchar **get_package_ids(PkBackend *backend, guint *count_p); gchar **get_strv_and_length(PkBackend *backend, const char *name, guint *count_p);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308281839.r7SIdPjf055158>