]> pd.if.org Git - zpackage/blobdiff - zpm-syncfs.c
rewrite zpm-add in C
[zpackage] / zpm-syncfs.c
index beff5608ef331083626a1468e7c424de7ea7477e..2360f7c167ee1ee658af6907f2a8a36c4618c5db 100644 (file)
@@ -229,6 +229,7 @@ static char *column(char *col, int ncols, char **vals, char **cols) {
 #define SYSERR(x) do { conf->log->error = 2; return conf->errabort; } while (0)
 
 
+/* TODO handle other ops properly */
 static char *ops[] = { "new", "remove", "update", 0 };
 
 enum op {
@@ -840,6 +841,14 @@ static int install(struct config *conf, struct nitem *item, unsigned int flags)
 
        source = conf->src ? conf->src : conf->log;
 
+       if (mkleading) {
+               rv = create_leading_dirs(item->dest);
+               if (!rv) {
+                       setsyserr(conf, "can't create leading dirs for %s", item->dest);
+                       return failure;
+               }
+       }
+
        if (unlink_file) {
                rv = remove_existing(conf, item->dest);
        } else if (rm_dir) {
@@ -850,14 +859,6 @@ static int install(struct config *conf, struct nitem *item, unsigned int flags)
                return failure;
        }
 
-       if (mkleading) {
-               rv = create_leading_dirs(item->dest);
-               if (!rv) {
-                       setsyserr(conf, "can't create leading dirs for %s", item->dest);
-                       return failure;
-               }
-       }
-
        errno = 0;
        switch (item->ftype) {
                case 'r': rv = zpm_extract(source, item->hash, item->dest, item->mode);
@@ -1108,7 +1109,7 @@ static void handle_config_files(struct config *conf) {
        }
        sqlite3_str_appendall(s, " as dest from syncinfo");
 
-       sqlite3_str_appendall(s," where configuration > 0");
+       sqlite3_str_appendall(s," where configuration > 0 and op in ('new','update','remove')");
 
        if (conf->reverse) {
                sqlite3_str_appendall(s," order by length(path) desc, path desc");
@@ -1241,7 +1242,7 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
        if (update) {
                if (!exist) {
                        /* warn, it should exist */
-                       fprintf(stderr, "%s missing, installing", nitem.dest);
+                       fprintf(stderr, "%s missing, installing\n", nitem.dest);
                        return install(conf, &nitem, 3);
                }
 
@@ -1277,13 +1278,14 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
                                /* fix md */
                                return set_md(conf, &nitem);
                        }
-                       if (mdsame && !hashsame) {
-                               /* install */
-                               return install(conf, &nitem, 3);
-                       }
-                       if (!mdsame && !hashsame) {
-                               /* install */
-                               return install(conf, &nitem, 3);
+
+                       if (!hashsame) {
+                               /* doesn't matter on the md */
+                               int flags = INS_MD | INS_CLD;
+                               if (nitem.ftype == 'l') {
+                                       flags |= INS_UNLINK;
+                               }
+                               return install(conf, &nitem, flags);
                        }
                }