+ if (eisdir) {
+ /* replacing old conf directory with a conf file.
+ * nothing needs to be done, if the directory
+ * is empty, it's ok to remove. if it's not empty,
+ * the install will fail
+ */
+ return 0;
+ }
+
+ /* replacing old file with new file */
+ /* new is same as on disk */
+ if (!(diffs & D_HASH)) {
+ return 0;
+ }
+
+ /* new is different than on disk, but on disk is same as old */
+ if (!(diffs & D_OHASH)) {
+ /* ok to do the update, since same as default */
+ fprintf(stderr, "updating default config %s\n", n->dest);
+ return 0;
+ }
+
+ /* new is different than on disk, and disk different than old */
+ /* log */
+ zpm_note_add(conf->log, n->pkglist, n->dest, n->hash,
+ "default config file update. zpm-cat %.8s", n->hash);
+ /* TODO check for note error */
+ return 1;
+
+}
+
+static int install_files(void *f, int ncols, char **vals, char **cols) {
+ struct config *conf = f;
+ struct nitem nitem;
+ struct stat existing;
+ int update = 0;
+
+ /* TODO put the result row in a hash table. May not actually
+ * be faster
+ */
+ if (!read_item(conf, ncols, vals, cols, &nitem)) {
+ fprintf(stderr, "can't read item\n");
+ return conf->errabort;
+ }
+
+ if (conf->verbose && !conf->dryrun) {
+ fprintf(stderr, "%s '%c' %s\n", nitem.opstr, nitem.ftype,
+ nitem.dest);
+ }
+
+ unsigned int diffs = file_compare(&nitem, &existing);
+ if (diffs >= D_ERROR) {
+ return seterror(conf, "can't check %s", nitem.dest);
+ }
+
+ /* updates:
+ * exist & same type & md same & hash same: do nothing, but warn bug
+ * exist & same type & md diff & hash same: fix md
+ * exist & same type & md same & hash diff: replace
+ * exist & same type & md diff & hash diff: replace & fix
+ * no exist: install and warn
+ * dir & not dir : remove, mkdir
+ * not dir & not dir & diff type: remove, install
+ * not dir & dir : remove dir if empty, error if not empty, install
+ *
+ * installs:
+ * no exist: create leading dirs, install
+ *
+ * exist & same type & md same & hash same & accept or over: do nothing
+ * exist & same & md diff or hash diff & overwrite : update
+ * exist & same & md diff or hash diff & accept : error, can't accept
+ * exist & same & md diff or hash diff & not accept : error
+ *
+ * exist & different type & not overwrite : error
+ * not dir & not dir & overwrite : remove and install
+ * not dir & dir & overwrite: remove empty or error, install
+ * dir & dir & overwrite: fix md
+ * dir & not dir & overwrite: remove and mkdir
+ */
+ int exist = (!(diffs & D_NOEXIST));
+ int sametype = (!(diffs & D_TYPE));
+ int mdsame = (!(diffs & D_MD));
+ int hashsame = (!(diffs & D_HASH));
+ int isdir = (diffs & D_ISDIR);
+ int eisdir = (diffs & D_EISDIR);
+ int accept = conf->absorb;
+ int overwrite = conf->overwrite;
+ int installing = (nitem.op == OP_NEW);
+ update = (nitem.op == OP_UPDATE);
+
+ if (update) {
+ if (!exist) {
+ /* warn, it should exist */
+ fprintf(stderr, "%s missing, installing", nitem.dest);
+ return install(conf, &nitem, 3);