From 7513a528f61259a92473284fd96313adb7a41f49 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Wed, 12 Sep 2018 11:09:20 +0000 Subject: [PATCH] add foreach_path to zpm library --- Makefile | 1 + lib/foreach_path.c | 36 ++++++++++++++++++++++++++++++++++++ zpm.h | 7 +++++++ 3 files changed, 44 insertions(+) create mode 100644 lib/foreach_path.c diff --git a/Makefile b/Makefile index e18f196..c477580 100644 --- a/Makefile +++ b/Makefile @@ -126,6 +126,7 @@ zpm-shell: sqlite/sqlite3.o sqlite/shell.o libzpm.a: lib/sha256.o lib/db.o lib/compress.o lib/uncompress.o lib/zpm.o \ sqlite/sqlite3.o lib/zpm_hash.o \ + lib/foreach_path.o \ lib/vercmp.o \ lib/sha256.o \ $(LZMAOBJ) diff --git a/lib/foreach_path.c b/lib/foreach_path.c new file mode 100644 index 0000000..271ee8c --- /dev/null +++ b/lib/foreach_path.c @@ -0,0 +1,36 @@ +#define _POSIX_C_SOURCE 2 +#include +#include +#include +#include + +#include + +#include "sqlite3.h" +#include "zpm.h" + +int zpm_foreach_path(struct zpm *zpm, char *pkgid, +int (*callback)(void *f, int ncols, char **vals, char **cols), +void *data, char **errmsg) { + + char *files = "select * from packagefiles where" + " printf('%%s-%%s-%%s', package, version, release) = %Q" + " order by path" + ; + + char *sql; + + sql = sqlite3_mprintf(files, pkgid); + if (!sql) { + return 0; + zpm->error = 1; + } + + zpm_exec(zpm, sql, callback, data, errmsg); + if (errmsg) { + zpm->error = 2; + return 0; + } + + return 1; +} diff --git a/zpm.h b/zpm.h index 68a536f..4a213c8 100644 --- a/zpm.h +++ b/zpm.h @@ -92,8 +92,11 @@ int zpm_checkinstall(struct zpm *local); int zpm_merge(struct zpm *z, struct zpm *src, uint32_t flags); +#if 0 void uncompresslzma(void *buf, size_t bufsize, FILE *out); void *compresslzma(void *buf, size_t bufsize, size_t *len); +#endif + #define SQLERROR(x) fprintf(stderr, "%s %d: %s\n", __func__, __LINE__, (x)) int zpm_hash(char *path, char *hash, uint32_t flags); int zpm_readopts(struct zpm *pkg, int ac, char **av); @@ -105,5 +108,9 @@ int zpm_addvercmp(struct zpm *pkg); int zpm_exec(struct zpm *z, const char *sql, int(*callback)(void *, int, char **, char**), void *arg, char **errmsg); +int zpm_foreach_path(struct zpm *zpm, char *pkgid, +int (*callback)(void *f, int ncols, char **vals, char **cols), +void *data, char **errmsg); + #endif -- 2.40.0