1 #define _POSIX_C_SOURCE 200809L
12 void zpm_file_init(struct zpm_file *file) {
22 file->confhash[0] = 0;
23 file->configuration = 0;
29 void zpm_file_free(struct zpm_file *file) {
40 #define getstring(x,n) ((const char *)sqlite3_column_text(x,n))
42 int zpm_foreach_path_ds(struct zpm *zpm, char *pkgid, char *where,
43 int (*callback)(struct zpm *, struct zpm_file *, void *),
48 struct zpm_file file = { 0 };
53 if (!zpm || zpm->error || !callback) return 0;
55 s = sqlite3_str_new(zpm->db);
56 sqlite3_str_appendall(s, "select package,version,release,path,filetype,mode,username,groupname,configuration,target,device,hash,confhash,status from packagefiles_status where ");
59 sqlite3_str_appendf(s, "%s", where);
61 sqlite3_str_appendall(s, "true");
65 sqlite3_str_appendf(s, " and printf('%%s-%%s-%%s', package, version, release) = %Q", pkgid);
68 sql = sqlite3_str_value(s);
70 sqlite3_str_finish(s);
75 st = zpm_dbquery(zpm, sql);
76 sqlite3_str_finish(s);
78 while (sqlite3_step(st) == SQLITE_ROW) {
81 val = getstring(st, 0);
82 file.package = val ? strdup(val) : 0;
84 val = getstring(st, 1);
85 file.version = val ? strdup(val) : 0;
87 file.release = sqlite3_column_int(st, 2);
89 val = getstring(st, 3);
90 file.path = val ? strdup(val) : 0;
92 val = getstring(st, 4);
93 file.type = val ? *val : 0;
95 val = getstring(st, 5);
96 file.mode = val ? strtol(val, NULL, 8) : 0;
98 val = getstring(st, 6);
99 file.owner = val ? strdup(val) : 0;
101 val = getstring(st, 7);
102 file.group = val ? strdup(val) : 0;
104 file.configuration = sqlite3_column_int(st, 8);
106 val = getstring(st, 9);
107 file.target = val ? strdup(val) : 0;
109 val = getstring(st, 10);
110 file.device = val ? strtol(val, NULL, 10) : 0;
112 val = getstring(st, 11);
114 strncpy(file.hash, val, ZPM_HASH_STRLEN);
115 file.hash[ZPM_HASH_STRLEN] = 0;
118 val = getstring(st, 12);
120 strncpy(file.hash, val, ZPM_HASH_STRLEN);
121 file.confhash[ZPM_HASH_STRLEN] = 0;
124 val = getstring(st, 13);
125 file.status = val ? strdup(val) : 0;
127 rv = callback(zpm, &file, data);
128 zpm_file_free(&file);
135 zpm->dbresult = sqlite3_finalize(st);
142 if (zpm->dbresult != SQLITE_OK) {
144 zpm->dberrmsg = strdup(sqlite3_errmsg(zpm->db));
153 int zpm_foreach_path(struct zpm *zpm, char *pkgid, char *where,
154 int (*callback)(void *f, int ncols, char **vals, char **cols),
155 void *data, char **errmsg) {
159 if (!zpm || zpm->error || !callback) return 0;
161 s = sqlite3_str_new(zpm->db);
162 sqlite3_str_appendall(s, "select * from packagefiles_status where ");
165 sqlite3_str_appendf(s, "%s", where);
167 sqlite3_str_appendall(s, "true");
171 sqlite3_str_appendf(s, " and printf('%%s-%%s-%%s', package, version, release) = %Q", pkgid);
174 sql = sqlite3_str_value(s);
176 sqlite3_str_finish(s);
181 zpm_exec(zpm, sql, callback, data, errmsg);
182 sqlite3_str_finish(s);
184 fprintf(stderr, "errmsg: %s\n", *errmsg);
192 int zpm_foreach_package(struct zpm *zpm, char *where,
193 int (*callback)(void *cbdata, int ncols, char **vals, char **cols),
194 void *data, char **errmsg) {
198 if (!zpm || zpm->error || !callback) return 0;
200 s = sqlite3_str_new(zpm->db);
201 sqlite3_str_appendall(s, "select * from packages_pkgid");
204 sqlite3_str_appendf(s, " where %s", where);
207 sql = sqlite3_str_value(s);
209 sqlite3_str_finish(s);
214 zpm_exec(zpm, sql, callback, data, errmsg);
215 sqlite3_str_finish(s);
217 fprintf(stderr, "errmsg: %s\n", *errmsg);