]> pd.if.org Git - zpackage/blobdiff - zpm-syncfs.c
fix compile process for elf programs
[zpackage] / zpm-syncfs.c
index 9889c606912875a60381ba243f5c1395591d8927..220ee039c38ab0428266f29e8c2e8d5580bc16c4 100644 (file)
@@ -32,10 +32,10 @@ struct config {
        int setuser, setgroup;
        int reverse, exitonerror;
        int overwrite, accept, acceptdir, ignoredirmd;
-       int ops_total, ops_completed;
-       int ops_remove, ops_remove_completed;
-       int ops_update, ops_update_completed;
-       int ops_install, ops_install_completed;
+       unsigned long ops_total, ops_completed;
+       unsigned long ops_remove, ops_remove_completed;
+       unsigned long ops_update, ops_update_completed;
+       unsigned long ops_install, ops_install_completed;
        int progress; /* type of progress meter */
 };
 
@@ -650,47 +650,56 @@ static int check_existing(void *f, int ncols, char **vals, char **cols) {
        return 0;
 }
 
+static void update_progress(struct config *conf, char *op, char *path) {
+       if (!conf->verbose) {
+               return;
+       }
+
+       if (conf->progress == 0) {
+               pdots(50, '.', conf->ops_completed-1, conf->ops_completed, conf->ops_total);
+       } else if (conf->progress == 1) {
+               size_t len = strlen(path);
+               int offset = 0;
+               if (len > 50) {
+                       offset = len-50;
+               }
+               printf("\r%lu/%lu %.10s %.50s\n", conf->ops_completed,
+                               conf->ops_total, op, path+offset);
+       } else if (conf->progress == 2) {
+               printf("%lu/%lu %s %s\n", conf->ops_completed,
+                               conf->ops_total, op, path);
+       }
+       fflush(stdout);
+}
+
 static int remove_files(void *f, int ncols, char **vals, char **cols) {
        struct config *conf = f;
        char *dest;
        struct stat st;
        int flags = 0;
 
+       conf->ops_completed++;
+
        dest = COL("dest");
+       char *ftype = COL("filetype");
+
        if (!dest) return seterror(conf,"no file dest");
+       if (!ftype) return seterror(conf,"no file type");
 
-       if (conf->dryrun) {
-               char *ftype = COL("filetype");
-               int t = *ftype;
+       update_progress(conf, *ftype == 'd' ? "rmdir" : "unlink", dest);
 
-               switch(t) {
-                       case 'd': printf("rmdir %s\n", dest); break;
-                       default: printf("unlink %s\n", dest); break;
-               }
-               fflush(stdout);
+       if (conf->dryrun) {
                return 0;
        }
 
-       if (conf->verbose) {
-               if (conf->progress == 2) {
-                       fprintf(stderr, "%s(%s)\n", flags ? "rmdir" : "unlink", dest);
-               } else if (conf->progress == 1) {
-                       /* overwrite */
-                       pdots(50, '.', conf->ops_completed, conf->ops_completed + 1, conf->ops_total);
-                       conf->ops_completed++;
-                       conf->ops_completed++;
-               } else {
-                       pdots(50, '.', conf->ops_completed, conf->ops_completed + 1, conf->ops_total);
-                       conf->ops_completed++;
-               }
-       }
-
        errno = 0;
 
        if (lstat(dest, &st) == -1) {
                switch (errno) {
                        case ENOENT:
-                               /* TODO chatter if verbose */
+                               if (conf->verbose > 1) {
+                                       fprintf(stderr, "expected file not found: '%s'\n", dest);
+                               }
                                break;
                        default:
                                return seterror(conf, "can't stat %s: %s", dest, strerror(errno));
@@ -702,6 +711,9 @@ static int remove_files(void *f, int ncols, char **vals, char **cols) {
                flags = AT_REMOVEDIR;
        }
        /* TODO check that expected filetype matches actual filetype */
+       /* alternatively, just use the expected type, skip the stat,
+        * and let it fail if the type is wrong
+        */
 
        errno = 0;
 
@@ -711,7 +723,7 @@ static int remove_files(void *f, int ncols, char **vals, char **cols) {
                                break;
                        case ENOTEMPTY: /* fall through */
                        case EEXIST:
-                               /* TODO chatter, or possibly require */
+                               fprintf(stderr, "expected empty directory: %s\n", dest);
                                break;
                        default:
                                return seterror(conf, "can't unlink %s: %s", dest, strerror(errno));
@@ -783,7 +795,6 @@ static int set_md(struct config *conf, struct nitem *item) {
                }
        }
 
-
        rv = utimensat(AT_FDCWD, item->dest, item->times, AT_SYMLINK_NOFOLLOW);
        if (rv == -1) {
                setsyserr(conf, "can't set mtime %.0f %s", (double)item->mtime,
@@ -930,7 +941,7 @@ static int adjust_for_config(struct nitem *n, unsigned int diffs) {
        int isdir = (diffs & D_ISDIR);
        int eisdir = (diffs & D_EISDIR);
        
-       /* TODO what if old was a directory? */
+       /* what if old was a directory? */
        if (!n->configuration) {
                /* replacing conf with non-conf */
                /* absorb file, mark todo */
@@ -1148,7 +1159,7 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
        struct stat existing;
        int update = 0;
 
-       /* TODO put the result row in a hash table.  May not actually
+       /* put the result row in a hash table?  May not actually
         * be faster
         */
        if (!read_item(conf, ncols, vals, cols, &nitem)) {
@@ -1162,20 +1173,10 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
        high = sqlite3_memory_highwater(0)/1024/1024;
        fprintf(stderr, "memory = %ld MB / %ld MB\n", used, high);
 #endif
-       if (conf->verbose && !conf->dryrun) {
-               if (conf->progress == 2) {
-                       fprintf(stderr, "%s '%c' %s\n", nitem.opstr, nitem.ftype,
-                                       nitem.dest);
-               } else if (conf->progress == 1) {
-                       /* overwrite */
-                       pdots(50, '.', conf->ops_completed, conf->ops_completed + 1, conf->ops_total);
-                       conf->ops_completed++;
-                       conf->ops_completed++;
-               } else {
-                       pdots(50, '.', conf->ops_completed, conf->ops_completed + 1, conf->ops_total);
-                       conf->ops_completed++;
-               }
-       }
+       char action[40];
+       sprintf(action, "%.8s %c", nitem.opstr, nitem.ftype);
+       conf->ops_completed++;
+       update_progress(conf, action, nitem.dest);
 
        unsigned int diffs = file_compare(&nitem, &existing);
        if (diffs >= D_ERROR) {
@@ -1261,6 +1262,7 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
                                 * and group, it might be correct on disk
                                 * but not as in the local database
                                 */
+
                                /* TODO detect whether this a logic bug or
                                 * an on-disk difference
                                 */
@@ -1332,7 +1334,9 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
                        }
 
                        if (!mdsame && isdir && conf->ignoredirmd) {
-                               /* TODO warn ignoring dir md */
+                               if (conf->verbose > 1) {
+                                       fprintf(stderr, "ignoring directory metadata difference: %s\n", nitem.dest);
+                               }
                                return 0;
                        }
 
@@ -1394,7 +1398,7 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
                                /* error */
                                return seterror(conf, "%s (md+hash): %s", accept ? "existing file not acceptable" : "file exists", nitem.dest);
                        }
-                       /* TODO error, should be impossible */
+                       /* error, should be impossible */
                        return seterror(conf, "impossible state reached");
                }
 
@@ -1413,9 +1417,7 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
                /* existing path is a directory */
                if (isdir) {
                        /* fix md */
-                       /* impossible, if isdir and eisdir, would
-                        * be same type
-                        * TODO
+                       /* impossible, if isdir and eisdir, would be same type
                         */
                        return set_md(conf, &nitem);
                } else {
@@ -1424,12 +1426,10 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
                        return install(conf, &nitem, 11);
                }
                /* if we get here, we missed a case */
-               /* TODO error */
                return seterror(conf, "impossible state 2 reached");
        }
 
-       /* TODO extra verbose print perms, mtime, etc, probably ls -l
-        * format
+       /* TODO extra verbose print perms, mtime, etc, probably ls -l format
         */ 
        if (conf->verbose) {
                printf("%s\n", nitem.path);
@@ -1568,7 +1568,7 @@ int main(int ac, char **av) {
        conf.errabort = 1;
        conf.errors = 0;
        conf.conflicts = 0;
-       conf.verbose = 0;
+       conf.verbose = 1;
        conf.dryrun = 0;
        conf.setuser = 1;
        conf.setgroup = 1;
@@ -1587,12 +1587,10 @@ int main(int ac, char **av) {
 
        localdbfile = ZPM_LOCAL_DB;
        if ((s = getenv("ZPMDB"))) {
-               /* TODO does this need to be copied ? */
                localdbfile = s;
        }
 
        if ((s = getenv("ZPM_ROOT_DIR"))) {
-               /* TODO does this need to be copied ? */
                conf.rootdir = s;
        }
 
@@ -1605,12 +1603,13 @@ int main(int ac, char **av) {
         *  args are pkgid triple, but will do a pkg find on the pkgdb
         */
 
-       while ((opt = getopt(ac, av, "f:d:c:nCR:vOAMDp")) != -1) {
+       while ((opt = getopt(ac, av, "f:d:c:nCR:vqOAMDp")) != -1) {
                switch (opt) {
                        case 'd': localdbfile = optarg; break;
                        case 'f': pkgdbfile = optarg; break;
                        case 'n': conf.dryrun = 1; break;
                        case 'v': conf.verbose++; break;
+                       case 'q': conf.verbose--; break;
                        case 'C': conf.errabort = 0; break;
                        case 'R': conf.rootdir = optarg; break;
                        case 'N': conf.setuser = 0; conf.setgroup = 0; break;
@@ -1647,8 +1646,6 @@ int main(int ac, char **av) {
                }
        }
 
-       /* TODO find pkgid from arg */
-
        /* TODO set conf var to finalize error reporting */
        if (conf.verbose) {
                fprintf(stderr, "syncing filesystem %s (ldb %s) from %s\n",
@@ -1689,10 +1686,10 @@ int main(int ac, char **av) {
                        conf.exitonerror = conf.dryrun ? 0 : 1;
                        conf.errabort = conf.dryrun ? 0 : 1;
                        count_ops(&conf);
-                       fprintf(stderr, "file ops: %d\n", conf.ops_total);
+                       fprintf(stderr, "file ops: %lu\n", conf.ops_total);
                        if (conf.ops_remove > 0) {
                                if (conf.verbose) {
-                                       fprintf(stderr, "removing %d file%s\n", conf.ops_remove, conf.ops_remove > 1 ? "s" : "");
+                                       fprintf(stderr, "removing %lu file%s\n", conf.ops_remove, conf.ops_remove > 1 ? "s" : "");
                                }
                                conf.reverse = 1;
                                conf.ops_completed = 0;
@@ -1706,7 +1703,7 @@ int main(int ac, char **av) {
 
                        if (conf.ops_update > 0) {
                                if (conf.verbose) {
-                                       fprintf(stderr, "updating %d file%s\n", conf.ops_update, conf.ops_update > 1 ? "s" : "");
+                                       fprintf(stderr, "updating %lu file%s\n", conf.ops_update, conf.ops_update > 1 ? "s" : "");
                                }
                                conf.reverse = 0;
                                conf.ops_completed = 0;
@@ -1720,7 +1717,7 @@ int main(int ac, char **av) {
 
                        if (conf.ops_install > 0) {
                                if (conf.verbose) {
-                                       fprintf(stderr, "installing %d file%s\n", conf.ops_install, conf.ops_install > 1 ? "s" : "");
+                                       fprintf(stderr, "installing %lu file%s\n", conf.ops_install, conf.ops_install > 1 ? "s" : "");
                                }
                                conf.reverse = 0;
                                conf.ops_completed = 0;