]> pd.if.org Git - zpackage/blobdiff - src/syncfs.c
remove stray debug fprintf
[zpackage] / src / syncfs.c
index 220ee039c38ab0428266f29e8c2e8d5580bc16c4..80a2ced30d17f112282a2f4e99879c88d1daf286 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "sqlite3.h"
 #include "zpm.h"
+#include "lib/buffer.h"
 
 struct config {
        struct zpm *log; /* logging db will be attached as "log" */
@@ -37,6 +38,7 @@ struct config {
        unsigned long ops_update, ops_update_completed;
        unsigned long ops_install, ops_install_completed;
        int progress; /* type of progress meter */
+       struct zpm_buffer note;
 };
 
 struct nitem {
@@ -58,7 +60,7 @@ struct nitem {
 };
 
 static void usage() {
-       printf("usage: zpm $scriptname [-fncC] args ...\n");
+       printf("usage: zpm syncfs ...\n");
 }
 
 static void warn(char *fmt, ...) {
@@ -70,6 +72,14 @@ static void warn(char *fmt, ...) {
        fprintf(stderr, "\n");
 }
 
+static void add_to_note(struct config *cf, char *fmt, ...) {
+       va_list ap;
+
+       va_start(ap, fmt);
+       zpm_buffer_appendvf(&cf->note, fmt, ap);
+       va_end(ap);
+}
+
 static void pdots(int len, int ch, int was, int now, int total) {
        was = len * was / total;
        if (now > total) {
@@ -349,7 +359,7 @@ static int read_item(struct config *conf, int ncols, char **vals, char **cols,
        n->ohash = COL("ohash");
        n->mds = COL("mds");
        n->omds = COL("omds");
-       n->pkglist = COL("pkglist");
+       n->pkglist = COL("pkgid");
 
        if (n->ftype == 'r') {
                n->hash = COL("hash");
@@ -1085,8 +1095,13 @@ static int config_handler(void *f, int ncols, char **vals, char **cols) {
                        save_config_file(conf, &nitem, save);
                }
                if (note) {
-                       zpm_note_add(conf->log, nitem.pkglist, nitem.path, nitem.hash,
-                                       note, nitem.hash);
+                       fprintf(stderr, "%s (%s) '%s' ", nitem.pkglist,
+                                       nitem.hash, nitem.path);
+                       fprintf(stderr, note, nitem.hash);
+                       fprintf(stderr, "\n");
+
+                       zpm_note_add(conf->log, nitem.pkglist, nitem.path,
+                                       nitem.hash, note, nitem.hash);
                }
        } else {
                if (save) {
@@ -1243,6 +1258,7 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
        if (update) {
                if (!exist) {
                        /* warn, it should exist */
+                       add_to_note(conf, "%s missing, installing\n", nitem.dest);
                        fprintf(stderr, "%s missing, installing\n", nitem.dest);
                        return install(conf, &nitem, 3);
                }
@@ -1515,6 +1531,8 @@ static void runstage(struct config *conf, char *stage,
        }
        if (conf->reverse) {
                sqlite3_str_appendall(s," order by length(path) desc, path desc");
+       } else {
+               sqlite3_str_appendall(s," order by length(path), path");
        }
 
        sql = sqlite3_str_value(s);
@@ -1579,6 +1597,7 @@ int main(int ac, char **av) {
        conf.overwrite = 0;
        conf.accept = 0;
        conf.acceptdir = 1;
+       zpm_buffer_init(&conf.note);
 
        if (geteuid() != 0) {
                conf.setuser = 0;
@@ -1648,9 +1667,9 @@ int main(int ac, char **av) {
 
        /* TODO set conf var to finalize error reporting */
        if (conf.verbose) {
-               fprintf(stderr, "syncing filesystem %s (ldb %s) from %s\n",
+               fprintf(stderr, "syncing filesystem %s (ldb %s)\n",
                                conf.rootdir ? conf.rootdir : "/",
-                               localdbfile, pkgdbfile);
+                               localdbfile);
        }
 
        conf.errors = 0;
@@ -1669,7 +1688,7 @@ int main(int ac, char **av) {
                        runstage(&conf, "new", check_existing);
                }
 
-               if (conf.verbose) {
+               if (conf.verbose && !conf.errors) {
                        fprintf(stderr, "beginning %ssync\n", conf.dryrun ?
                                        "dryrun " : "");
                }
@@ -1733,5 +1752,7 @@ int main(int ac, char **av) {
 
        zpm_close(&localdb);
        zpm_close(conf.src);
+       /* TODO add the note */
+       zpm_buffer_free(&conf.note);
        return conf.errors ? 1 : 0;
 }