]> pd.if.org Git - zpackage/commitdiff
add foreach_path to zpm library
authorNathan Wagner <nw@hydaspes.if.org>
Wed, 12 Sep 2018 11:09:20 +0000 (11:09 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Wed, 12 Sep 2018 11:10:32 +0000 (11:10 +0000)
Makefile
lib/foreach_path.c [new file with mode: 0644]
zpm.h

index e18f196d47eb8980ecffcea151d98b1bc12adab3..c477580aad986979d694665fd663837939850af1 100644 (file)
--- 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 (file)
index 0000000..271ee8c
--- /dev/null
@@ -0,0 +1,36 @@
+#define _POSIX_C_SOURCE 2
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <string.h>
+
+#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 68a536ffd2a03d323f36fdb20e603d001552e4ac..4a213c853e5171d8f3efd915ecd43b93b27b8283 100644 (file)
--- 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