1 #define _POSIX_C_SOURCE 200112L
10 #include <sys/types.h>
16 #include "t/ctap/ctap.h"
29 int check_content; /* ignored for config files */
34 printf("usage: zpm foreach-path [-fncC] args ...\n");
37 static char *column(char *col, int ncols, char **vals, char **cols) {
41 for (i=0; i < ncols; i++) {
42 if (!strcmp(col, cols[i])) {
50 static int count_plan(void *f, int ncols, char **vals, char **cols) {
51 struct config *conf = f;
53 int ftype, configfile = 0;
56 v = column("filetype", ncols, vals, cols);
58 v = column("configuration", ncols, vals, cols);
63 if (ftype == 'r' && !configfile) {
72 static int verify(void *f, int ncols, char **vals, char **cols) {
73 struct config *conf = f;
77 int ftype, configfile = 0;
78 char *v, *hash, ehash[ZPM_HASH_STRLEN+1];
80 path = column("path", ncols, vals, cols);
81 hash = column("hash", ncols, vals, cols);
82 v = column("filetype", ncols, vals, cols);
84 v = column("configuration", ncols, vals, cols);
91 rv = lstat(path, &st);
94 case ENOENT: ok(0, "%s does not exist", path);
96 default: ok(0, "cannot stat %s: %s", path, strerror(errno));
100 if (ftype == 'r' && !configfile) {
106 ok(1, "%s exists", path);
108 if (ftype == 'r' && !configfile) {
109 zpm_hash(path, ehash, 0);
110 if (!is_string(ehash, hash, "hash %s", path)) {
118 int main(int ac, char **av) {
124 struct config conf = { 0 };
125 conf.dbfile = "/var/lib/zpm/local.db";
127 if ((s = getenv("ZPMDB"))) {
128 /* TODO does this need to be copied ? */
132 while ((opt = getopt(ac, av, "f:")) != -1) {
134 case 'f': conf.dbfile = optarg;
145 if (!zpm_open(&pkg, conf.dbfile)) {
146 fprintf(stderr, "can't open zpm db %s\n", conf.dbfile);
155 fprintf(stderr, "must specify pkgid\n");
160 /* TODO lookup pkgid via zpm-findpkg equivalent */
162 if (!zpm_foreach_path(&pkg, pkgid, 0, count_plan, &conf, &errmsg)) {
164 fprintf(stderr, "database error: %s\n", errmsg);
167 if (pkg.error == 1) {
168 fprintf(stderr, "unable to allocate memory\n");
170 fprintf(stderr, "unable to plan\n");
176 if (!zpm_foreach_path(&pkg, pkgid, 0, verify, &conf, &errmsg)) {
178 fprintf(stderr, "database error: %s\n", errmsg);
181 if (pkg.error == 1) {
182 fprintf(stderr, "unable to allocate memory\n");
188 return conf.failed ? 1 : 0;