+static void check_conflicts(struct config *conf, char *conflict_type,
+ int (callback)(void *, int, char **, char **)) {
+ int rv;
+ char *errmsg;
+ sqlite3_str *s;
+ char *sql;
+
+ s = sqlite3_str_new(conf->log->db);
+ sqlite3_str_appendall(s, "select *, ");
+ if (conf->rootdir) {
+ sqlite3_str_appendf(s, "printf('%%s/%%s',rtrim(%Q,'/'),ltrim(path,'/'))", conf->rootdir);
+ } else {
+ sqlite3_str_appendf(s, "printf('/%%s', trim(path, '/'))");
+ }
+ sqlite3_str_appendall(s, " as dest from syncconflicts");
+
+ if (conflict_type) {
+ sqlite3_str_appendf(s," where conflict = %Q", conflict_type);
+ }
+ if (conf->reverse) {
+ sqlite3_str_appendall(s," order by length(path) desc, path desc,pkgid collate vercmp desc, conflict desc");
+ } else {
+ sqlite3_str_appendall(s," order by length(path), path, pkgid collate vercmp, conflict");
+
+ }
+
+ sql = sqlite3_str_value(s);
+ if (conf->verbose > 2) {
+ fprintf(stderr, "stage query: %s\n", sql);
+ }
+
+ rv = zpm_exec(conf->log, sql, callback, conf, &errmsg);
+
+ sqlite3_str_finish(s);
+
+ if (rv) {
+ fprintf(stderr, "exec fail: %s\n", sqlite3_errstr(rv));
+ if (errmsg) {
+ fprintf(stderr, "database error: %s\n", errmsg);
+ conf->errors++;
+ }
+ if (conf->log->error == 1) {
+ fprintf(stderr, "unable to allocate memory\n");
+ }
+ fprintf(stderr, "zpm_exec failure: %s\n",
+ conf->log->errmsg ? conf->log->errmsg : "unknown");
+ conf->errors++;
+ }
+ if (conf->log->errmsg) {
+ fprintf(stderr, "error: %s\n", conf->log->errmsg);
+ }
+ if (conf->errors && conf->exitonerror) {
+ zpm_close(conf->log);
+ zpm_close(conf->src);
+ exit(EXIT_FAILURE);
+ }
+ /* TODO final report function in conf var */
+}
+