1 #define _POSIX_C_SOURCE 200112L
10 #include <sys/types.h>
17 #include "t/ctap/ctap.h"
30 int check_content; /* ignored for config files */
35 printf("usage: zpm foreach-path [-fncC] args ...\n");
38 static char *column(char *col, int ncols, char **vals, char **cols) {
42 for (i=0; i < ncols; i++) {
43 if (!strcmp(col, cols[i])) {
51 static int count_plan(void *f, int ncols, char **vals, char **cols) {
52 struct config *conf = f;
54 int ftype, configfile = 0;
57 v = column("filetype", ncols, vals, cols);
59 v = column("configuration", ncols, vals, cols);
64 if (ftype == 'r' && !configfile) {
73 static int verify(void *f, int ncols, char **vals, char **cols) {
74 struct config *conf = f;
78 int ftype, configfile = 0;
79 char *v, *hash, ehash[ZPM_HASH_STRLEN+1];
81 path = column("path", ncols, vals, cols);
82 hash = column("hash", ncols, vals, cols);
83 v = column("filetype", ncols, vals, cols);
85 v = column("configuration", ncols, vals, cols);
92 rv = lstat(path, &st);
95 case ENOENT: ok(0, "%s does not exist", path);
97 default: ok(0, "cannot stat %s: %s", path, strerror(errno));
101 if (ftype == 'r' && !configfile) {
107 ok(1, "%s exists", path);
109 if (ftype == 'r' && !configfile) {
110 zpm_hash(path, ehash, 0);
111 if (!is_string(ehash, hash, "hash %s", path)) {
119 int main(int ac, char **av) {
125 struct config conf = { 0 };
126 conf.dbfile = "/var/lib/zpm/local.db";
128 if ((s = getenv("ZPMDB"))) {
129 /* TODO does this need to be copied ? */
133 while ((opt = getopt(ac, av, "f:")) != -1) {
135 case 'f': conf.dbfile = optarg;
146 if (!zpm_open(&pkg, conf.dbfile)) {
147 fprintf(stderr, "can't open zpm db %s\n", conf.dbfile);
156 fprintf(stderr, "must specify pkgid\n");
161 /* TODO lookup pkgid via zpm-findpkg equivalent */
163 if (!zpm_foreach_path(&pkg, pkgid, 0, count_plan, &conf, &errmsg)) {
165 fprintf(stderr, "database error: %s\n", errmsg);
168 if (pkg.error == 1) {
169 fprintf(stderr, "unable to allocate memory\n");
171 fprintf(stderr, "unable to plan\n");
177 if (!zpm_foreach_path(&pkg, pkgid, 0, verify, &conf, &errmsg)) {
179 fprintf(stderr, "database error: %s\n", errmsg);
182 if (pkg.error == 1) {
183 fprintf(stderr, "unable to allocate memory\n");
189 return conf.failed ? 1 : 0;