1 #define _POSIX_C_SOURCE 200809L
17 /* needed for S_IFMT and AT_FDCWD */
26 struct zpm *log; /* logging db will be attached as "log" */
30 int errabort, errors, verbose, dryrun, conflicts;
31 int setuser, setgroup;
32 int reverse, exitonerror;
33 int overwrite, absorb;
46 char *pkglist; /* space separated */
51 struct timespec times[2];
55 printf("usage: zpm $scriptname [-fncC] args ...\n");
58 static int seterror(struct config *conf, char *msgfmt, ...) {
65 vsnprintf(msg, sizeof msg, msgfmt, ap);
69 if (conf->log->errmsg) {
70 free(conf->log->errmsg);
73 conf->log->errmsg = strdup(msg);
76 fprintf(stderr, "%s\n", msg);
79 return conf->errabort;
82 static int setsyserr(struct config *conf, char *msgfmt, ...) {
90 printed = vsnprintf(msg, sizeof msg, msgfmt, ap);
94 /* nothing we can really do */
95 return conf->errabort;
98 if ((size_t)printed < sizeof msg) {
99 snprintf(msg+printed, sizeof msg - printed, ": %s",
104 if (conf->log->errmsg) {
105 free(conf->log->errmsg);
108 conf->log->errmsg = strdup(msg);
111 fprintf(stderr, "%s\n", msg);
114 return conf->errabort;
117 static int exists(char *path, mode_t *mode) {
120 if (lstat(path, &st) == -1) {
123 if (mode) *mode = st.st_mode;
127 /* TODO maintain a list of already created directories */
128 static int create_leading_dirs(char *path) {
131 char pcopy[ZPM_PATH_MAX];
136 delim = strrchr(pcopy, '/');
137 if (!delim) return 1; /* not an error, but no leading dirs */
139 /* cut off last component */
148 delim = strchr(s, '/');
154 /* try to create the directory, if it exists
155 * and is a directory or a symlink, that's ok
156 * should be (eventually) a symlink to a directory
157 * so we want stat here, not lstat
159 if (mkdir(pcopy, 0755) == -1) {
162 if (stat(pcopy, &st) == -1) {
166 switch (st.st_mode & S_IFMT) {
186 static char *column(char *col, int ncols, char **vals, char **cols) {
190 for (i=0; i < ncols; i++) {
191 // fprintf(stderr, "checking '%s' = '%s'\n", cols[i], vals[i]);
193 if (!strcmp(col, cols[i])) {
201 #define COL(x) column(x, ncols, vals, cols)
202 #define SYSERR(x) do { conf->log->error = 2; return conf->errabort; } while (0)
205 static char *ops[] = { "new", "remove", "update", 0 };
213 static int getop(char *opstr) {
216 if (!opstr) return 0;
217 for (i=0;ops[i];i++) {
218 if (!strcmp(opstr, ops[i])) {
225 static int report_conflicts(void *f, int ncols, char **vals, char **cols) {
226 struct config *conf = f;
227 char *path, *hash, *pkg, *conflict_type, *mds;
231 conflict_type = COL("conflict");
232 if (!strcmp(conflict_type, "hash")) {
234 fprintf(stderr, "hash conflict: package %s path %s hash %.8s\n",
237 if (!strcmp(conflict_type, "md")) {
239 fprintf(stderr, "md conflict: package %s path %s md %s\n",
242 fprintf(stderr, "%s conflict: package %s path %s\n",
243 conflict_type, pkg, path);
250 static int check_existing(void *f, int ncols, char **vals, char **cols) {
251 struct config *conf = f;
257 return seterror(conf, "no path");
261 printf("checkfor %s\n", path);
267 fprintf(stderr, "check for existing %s\n", path);
270 if (lstat(path, &st) == 0) {
271 fprintf(stderr, "%s exists\n", path);
275 /* not an error, file shouldn't exist*/
278 fprintf(stderr, "unable to check %s: %s\n",
279 path, strerror(errno));
287 static int remove_files(void *f, int ncols, char **vals, char **cols) {
288 struct config *conf = f;
294 if (!dest) return seterror(conf,"no file dest");
297 char *ftype = COL("filetype");
301 case 'd': printf("rmdir %s\n", dest); break;
302 default: printf("unlink %s\n", dest); break;
308 if (lstat(dest, &st) == -1) {
309 return seterror(conf,"can't stat");
312 if (S_ISDIR(st.st_mode)) {
313 flags = AT_REMOVEDIR;
315 /* TODO check that expected filetype matches actual filetype */
318 fprintf(stderr, "%s(%s)\n", flags ? "rmdir" : "unlink", dest);
323 if (unlinkat(AT_FDCWD, dest, flags) == -1) {
328 return seterror(conf, "can't unlink");
335 #define MARK fprintf(stderr, "%s %d: mark\n", __func__, __LINE__)
337 #define D_NOEXIST 0x1
342 #define D_EISDIR 0x20
346 #define D_MTIME 0x200
347 #define D_OHASH 0x400
348 #define D_ERROR 0x1000
349 #define D_STATERROR 0x2000
350 #define D_RLERROR 0x4000
352 /* 1 = file doesn't exist, 2 = file is a directory, target isn't */
353 /* 4 == ftype different */
354 /* 8 = hash different when both are regular files */
355 static unsigned int file_compare(struct nitem *n, struct stat *st) {
356 int etype = 0, stat_type;
357 char ehash[ZPM_HASH_STRLEN+1];
358 unsigned int diff = 0;
363 case 'd': etype = S_IFDIR; diff |= D_ISDIR ; break;
364 case 'r': etype = S_IFREG; break;
365 case 'l': etype = S_IFLNK; break;
366 default: etype = 0; break;
370 /* new file, so check type, hash, etc */
371 if (lstat(n->dest, st) == 0) {
372 stat_type = st->st_mode & S_IFMT;
373 if (stat_type != etype) {
376 if (stat_type == S_IFDIR) {
380 if (n->hash && etype == S_IFREG && stat_type == S_IFREG) {
381 zpm_hash(n->dest, ehash, 0);
382 if (strcmp(n->hash, ehash) != 0) {
385 if (n->ohash && strcmp(n->ohash, ehash) != 0) {
389 if (n->hash && etype == S_IFLNK && stat_type == S_IFLNK) {
390 lsize = readlink(n->dest, link, sizeof link);
391 if (lsize == -1 || lsize == sizeof link) {
394 } else if (strcmp(n->target, link) != 0) {
398 if (n->uid != st->st_uid) {
402 if (n->gid != st->st_gid) {
406 if (n->mode != (st->st_mode & 07777)) {
412 case ENOENT: diff |= D_NOEXIST; break;
413 default: diff |= (D_STATERROR|D_ERROR); break;
420 static int read_item(struct config *conf, int ncols, char **vals, char **cols,
425 struct nitem zero = { 0 };
431 seterror(conf, "can't determine op");
437 seterror(conf, "can't determine op");
441 n->path = COL("path");
443 seterror(conf, "no file path");
446 if (strlen(n->path) == 0) {
447 seterror(conf, "zero length path not allowed");
451 /* TODO config to dishonor setuid/setgid */
452 n->dest = COL("dest");
454 seterror(conf, "no file dest");
458 if (strlen(n->dest) == 0) {
459 seterror(conf, "zero length dest not allowed");
466 seterror(conf, "can't determine mode");
470 n->mode = strtoul(val, NULL, 8);
472 val = COL("configuration");
474 seterror(conf, "can't determine config status");
477 n->configuration = strtoul(val, NULL, 10);
479 val = COL("filetype");
480 if (!val || strlen(val) == 0) {
481 seterror(conf, "can't determine file type");
486 /* these can be null */
487 n->ohash = COL("ohash");
489 n->omds = COL("omds");
490 n->pkglist = COL("pkglist");
492 if (n->ftype == 'r') {
493 n->hash = COL("hash");
495 seterror(conf, "can't get hash");
498 } else if (n->ftype == 'l') {
499 n->target = COL("target");
501 seterror(conf, "can't get target");
504 if (strlen(n->target) == 0) {
505 seterror(conf, "zero length target not allowed");
512 val = COL("username");
514 seterror(conf, "no username");
519 seterror(conf, "no passwd entry");
527 if (conf->setgroup) {
528 val = COL("groupname");
530 seterror(conf, "no groupname");
535 seterror(conf, "no group entry");
544 double mtime = strtod(COL("mtime"),NULL);
546 mtime = (double)time(NULL);
549 n->mtime = (time_t)mtime;
551 n->times[0].tv_sec = 0;
552 n->times[0].tv_nsec = UTIME_OMIT;
553 n->times[1].tv_sec = (time_t)llrint(floor(mtime));
554 n->times[1].tv_nsec = lrint(floor(fmod(mtime,1.0)*1000000000));
559 static int remove_dir(struct config *conf, char *path) {
564 setsyserr(conf, "can't rmdir %s", path);
570 static int remove_existing(struct config *conf, char *path) {
575 setsyserr(conf, "can't unlink %s", path);
581 static int set_md(struct config *conf, struct nitem *item) {
586 printf("chmod %o %s\n", item->mode, item->dest);
587 if (conf->setuser && conf->setgroup) {
588 printf("chown %d:%d %s\n", item->uid, item->gid,
591 printf("mtime %.0f %s\n", (double)item->mtime, item->dest);
596 rv = chmod(item->dest, item->mode);
599 setsyserr(conf, "can't chmod %o %s", item->mode, item->dest);
600 return conf->errabort;
603 if (conf->setuser && conf->setgroup) {
604 rv = chown(item->dest, item->uid, item->gid);
606 setsyserr(conf, "can't chown %s", item->dest);
607 return conf->errabort;
611 rv = utimensat(AT_FDCWD, item->dest, item->times, AT_SYMLINK_NOFOLLOW);
613 setsyserr(conf, "can't set mtime %.0f %s", (double)item->mtime,
615 return conf->errabort;
620 /* install a file or create a directory or symlink. path should not exist
623 /* flags: 1 = set md, 2 = create leading dirs, 4 = unlink existing file,
624 * 8 = rmdir existing dir, 16 = return true/false
628 #define INS_UNLINK 0x4
629 #define INS_RMDIR 0x8
631 #define INS_ZPMNEW 0x20
632 static int install(struct config *conf, struct nitem *item, unsigned int flags) {
636 int mkleading = (flags & 2);
637 int setmd = (flags & 1);
638 int unlink_file = (flags & 4);
639 int rm_dir = (flags & 8);
640 int failure = conf->errabort;
650 printf("unlink %s\n", item->dest);
652 printf("rmdir %s\n", item->dest);
655 printf("install %c%o %d:%d %s -> %s\n", item->ftype,
656 item->mode, item->uid, item->gid, item->path,
662 source = conf->src ? conf->src : conf->log;
665 rv = remove_existing(conf, item->dest);
667 rv = remove_dir(conf, item->dest);
675 rv = create_leading_dirs(item->dest);
677 setsyserr(conf, "can't create leading dirs for %s", item->dest);
682 if (item->ftype == 'r') {
683 rv = zpm_extract(source, item->hash, item->dest, item->mode);
685 seterror(conf, "can't extract %s", item->dest);
691 switch (item->ftype) {
692 case 'd': rv = mkdir(item->dest, item->mode);
694 case 'l': rv = symlink(item->target, item->dest);
701 setsyserr(conf, "installing %s failed", item->dest);
706 return set_md(conf, item) == 0 ? success : failure;
715 static int adjust_for_config(struct config *conf, struct nitem *n, unsigned int
718 if (!n->oldwasconf) {
722 /* TODO what if old was a directory? */
723 if (!n->configuration) {
724 /* replacing conf with non-conf */
725 /* absorb file, mark todo */
726 char hash[ZPM_HASH_STRLEN+1];
727 if (zpm_import(conf->log, n->dest, 0, hash)) {
728 zpm_note_add(conf->log, n->pkglist, n->dest, hash,
729 "replaced config file with non-config. zpm-cat %.8s", hash);
731 fprintf(stderr, "unable to import existing config file %s\n", n->dest);
737 int sametype = (!(diffs & D_TYPE));
738 int isdir = (diffs & D_ISDIR);
739 int eisdir = (diffs & D_EISDIR);
741 /* both old and new are config files */
742 if (isdir && sametype) {
743 /* both config directories, can only be changing
744 * metadata, so no adjustment needed
750 char hash[ZPM_HASH_STRLEN+1];
752 /* replacing old file with new directory */
753 /* absorb, make note */
754 if (zpm_import(conf->log, n->dest, 0, hash)) {
755 zpm_note_add(conf->log, n->pkglist, n->dest, hash,
756 "replaced config file with config directory. zpm-cat %.8s", hash);
758 fprintf(stderr, "unable to import existing config file %s\n", n->dest);
765 /* replacing old conf directory with a conf file.
766 * nothing needs to be done, if the directory
767 * is empty, it's ok to remove. if it's not empty,
768 * the install will fail
773 /* replacing old file with new file */
774 /* new is same as on disk */
775 if (!(diffs & D_HASH)) {
779 /* new is different than on disk, but on disk is same as old */
780 if (!(diffs & D_OHASH)) {
781 /* ok to do the update, since same as default */
782 fprintf(stderr, "updating default config %s\n", n->dest);
786 /* new is different than on disk, and disk different than old */
788 zpm_note_add(conf->log, n->pkglist, n->dest, n->hash,
789 "default config file update. zpm-cat %.8s", n->hash);
790 /* TODO check for note error */
795 static int install_files(void *f, int ncols, char **vals, char **cols) {
796 struct config *conf = f;
798 struct stat existing;
801 /* TODO put the result row in a hash table. May not actually
804 if (!read_item(conf, ncols, vals, cols, &nitem)) {
805 fprintf(stderr, "can't read item\n");
806 return conf->errabort;
809 if (conf->verbose && !conf->dryrun) {
810 fprintf(stderr, "%s '%c' %s\n", nitem.opstr, nitem.ftype,
814 unsigned int diffs = file_compare(&nitem, &existing);
815 if (diffs >= D_ERROR) {
816 return seterror(conf, "can't check %s", nitem.dest);
820 * exist & same type & md same & hash same: do nothing, but warn bug
821 * exist & same type & md diff & hash same: fix md
822 * exist & same type & md same & hash diff: replace
823 * exist & same type & md diff & hash diff: replace & fix
824 * no exist: install and warn
825 * dir & not dir : remove, mkdir
826 * not dir & not dir & diff type: remove, install
827 * not dir & dir : remove dir if empty, error if not empty, install
830 * no exist: create leading dirs, install
832 * exist & same type & md same & hash same & accept or over: do nothing
833 * exist & same & md diff or hash diff & overwrite : update
834 * exist & same & md diff or hash diff & accept : error, can't accept
835 * exist & same & md diff or hash diff & not accept : error
837 * exist & different type & not overwrite : error
838 * not dir & not dir & overwrite : remove and install
839 * not dir & dir & overwrite: remove empty or error, install
840 * dir & dir & overwrite: fix md
841 * dir & not dir & overwrite: remove and mkdir
843 int exist = (!(diffs & D_NOEXIST));
844 int sametype = (!(diffs & D_TYPE));
845 int mdsame = (!(diffs & D_MD));
846 int hashsame = (!(diffs & D_HASH));
847 int isdir = (diffs & D_ISDIR);
848 int eisdir = (diffs & D_EISDIR);
849 int accept = conf->absorb;
850 int overwrite = conf->overwrite;
851 int installing = (nitem.op == OP_NEW);
852 update = (nitem.op == OP_UPDATE);
856 /* warn, it should exist */
857 fprintf(stderr, "%s missing, installing", nitem.dest);
858 return install(conf, &nitem, 3);
861 switch (adjust_for_config(conf, &nitem, diffs)) {
862 case -1: return conf->errabort; break;
864 fprintf(stderr, "skipping changed default config file: %s\n", nitem.dest);
869 /* file exists in filesystem */
871 if (mdsame && hashsame) {
872 /* warn, bug in logic. This shouldn't occur,
873 * because if there is nothing to do, it
874 * shouldn't be listed as an update
876 /* could be an update. We're checking against
877 * what's actually on disk, not what was
878 * expected to have been on disk. So, if
879 * the admin has modified the file, or if
880 * it had been installed ignoring the user
881 * and group, it might be correct on disk
882 * but not as in the local database
884 /* TODO detect whether this a logic bug or
885 * an on-disk difference
888 fprintf(stderr, "%s should not be an update\n", nitem.dest);
889 fprintf(stderr, "old hash: %s\n", nitem.ohash);
890 fprintf(stderr, "new hash: %s\n", nitem.hash);
891 fprintf(stderr, "old mds: %s\n", nitem.omds);
892 fprintf(stderr, "new mds: %s\n", nitem.mds);
897 if (!mdsame && hashsame) {
899 return set_md(conf, &nitem);
901 if (mdsame && !hashsame) {
903 return install(conf, &nitem, 3);
905 if (!mdsame && !hashsame) {
907 return install(conf, &nitem, 3);
911 /* file exists, and is not the same type */
913 if (isdir && !eisdir) {
914 /* remove existing */
916 return install(conf, &nitem, 7);
918 if (!isdir && eisdir) {
919 /* remove dir, or error */
921 return install(conf, &nitem, 11);
923 if (!isdir && !isdir) {
924 /* necessarily !sametype, sametype handled above */
925 /* remove existing */
927 return install(conf, &nitem, 7);
929 /* error, should not be possible, assert(0)? */
930 fprintf(stderr,"impossible state: %s:%d\n", __func__, __LINE__);
935 return install(conf, &nitem, 3);
938 /* file exists in filesystem */
940 if (mdsame && hashsame && (accept || overwrite)) {
942 if (conf->dryrun || conf->verbose) {
943 fprintf(stderr, "accepting existing file: %s\n", nitem.dest);
947 if (mdsame && hashsame && !(accept || overwrite)) {
949 return seterror(conf, "will not accept or overwrite existing file: %s", nitem.dest);
951 if (mdsame && !hashsame && overwrite) {
953 return install(conf, &nitem, eisdir ? 11 : 7);
955 if (mdsame && !hashsame && !overwrite) {
956 /* accept doesn't matter, since it's
957 * not an acceptable file */
959 return seterror(conf, "%s (hashdiff): %s", accept ? "existing file not acceptable" : "file exists", nitem.dest);
961 if (!mdsame && hashsame && overwrite) {
963 return set_md(conf, &nitem);
965 if (!mdsame && hashsame && !overwrite) {
966 /* accept doesn't matter, since it's
967 * not an acceptable file */
969 return seterror(conf, "%s (mddiff): %s", accept ? "existing file not acceptable" : "file exists", nitem.dest);
971 if (!mdsame && !hashsame && overwrite) {
973 return install(conf, &nitem, eisdir ? 11 : 7);
975 if (!mdsame && !hashsame && !overwrite) {
976 /* accept doesn't matter, since it's
977 * not an acceptable file */
979 return seterror(conf, "%s (md+hash): %s", accept ? "existing file not acceptable" : "file exists", nitem.dest);
981 /* TODO error, should be impossible */
982 return seterror(conf, "impossible state reached");
985 /* file exists, and is not the same type */
988 return seterror(conf, "%s (difftype): %s", accept ? "existing file not acceptable" : "file exists", nitem.dest);
991 /* not the same type, but ok to overwrite */
993 /* remove existing */
994 return install(conf, &nitem, 7);
997 /* existing path is a directory */
1000 /* impossible, if isdir and eisdir, would
1004 return set_md(conf, &nitem);
1006 /* remove empty dir or error */
1008 return install(conf, &nitem, 11);
1010 /* if we get here, we missed a case */
1012 return seterror(conf, "impossible state 2 reached");
1015 /* TODO extra verbose print perms, mtime, etc, probably ls -l
1018 if (conf->verbose) {
1019 printf("%s\n", nitem.path);
1025 static void check_conflicts(struct config *conf, char *conflict_type,
1026 int (callback)(void *, int, char **, char **)) {
1032 s = sqlite3_str_new(conf->log->db);
1033 sqlite3_str_appendall(s, "select *, ");
1034 if (conf->rootdir) {
1035 sqlite3_str_appendf(s, "printf('%%s/%%s',rtrim(%Q,'/'),ltrim(path,'/'))", conf->rootdir);
1037 sqlite3_str_appendf(s, "printf('/%%s', trim(path, '/'))");
1039 sqlite3_str_appendall(s, " as dest from syncconflicts");
1041 if (conflict_type) {
1042 sqlite3_str_appendf(s," where conflict = %Q", conflict_type);
1044 if (conf->reverse) {
1045 sqlite3_str_appendall(s," order by length(path) desc, path desc,pkgid collate vercmp desc, conflict desc");
1047 sqlite3_str_appendall(s," order by length(path), path, pkgid collate vercmp, conflict");
1051 sql = sqlite3_str_value(s);
1053 rv = zpm_exec(conf->log, sql, callback, conf, &errmsg);
1055 sqlite3_str_finish(s);
1058 fprintf(stderr, "exec fail: %s\n", sqlite3_errstr(rv));
1060 fprintf(stderr, "database error: %s\n", errmsg);
1063 if (conf->log->error == 1) {
1064 fprintf(stderr, "unable to allocate memory\n");
1066 fprintf(stderr, "zpm_exec failure: %s\n",
1067 conf->log->errmsg ? conf->log->errmsg : "unknown");
1070 if (conf->log->errmsg) {
1071 fprintf(stderr, "error: %s\n", conf->log->errmsg);
1073 if (conf->errors && conf->exitonerror) {
1074 zpm_close(conf->log);
1075 zpm_close(conf->src);
1078 /* TODO final report function in conf var */
1081 static void runstage(struct config *conf, char *stage,
1082 int (callback)(void *, int, char **, char **)) {
1088 s = sqlite3_str_new(conf->log->db);
1089 sqlite3_str_appendall(s, "select *, ");
1090 if (conf->rootdir) {
1091 sqlite3_str_appendf(s, "printf('%%s/%%s',rtrim(%Q,'/'),ltrim(path,'/'))", conf->rootdir);
1093 sqlite3_str_appendf(s, "printf('/%%s', trim(path, '/'))");
1095 sqlite3_str_appendall(s, " as dest from syncinfo");
1098 sqlite3_str_appendf(s," where op = %Q", stage);
1100 if (conf->reverse) {
1101 sqlite3_str_appendall(s," order by length(path) desc, path desc");
1104 sql = sqlite3_str_value(s);
1106 rv = zpm_exec(conf->log, sql, callback, conf, &errmsg);
1108 sqlite3_str_finish(s);
1111 fprintf(stderr, "exec fail: %s\n", sqlite3_errstr(rv));
1113 fprintf(stderr, "database error: %s\n", errmsg);
1116 if (conf->log->error == 1) {
1117 fprintf(stderr, "unable to allocate memory\n");
1119 fprintf(stderr, "zpm_exec failure: %s\n",
1120 conf->log->errmsg ? conf->log->errmsg : "unknown");
1124 if (conf->log->errmsg) {
1125 fprintf(stderr, "error: %s\n", conf->log->errmsg);
1128 if (conf->errors && conf->exitonerror) {
1129 zpm_close(conf->log);
1130 zpm_close(conf->src);
1133 /* TODO final report function in conf var */
1136 int main(int ac, char **av){
1140 char *pkgdbfile = 0, *localdbfile = 0;
1159 if (geteuid() != 0) {
1164 localdbfile = ZPM_LOCAL_DB;
1165 if ((s = getenv("ZPMDB"))) {
1166 /* TODO does this need to be copied ? */
1170 if ((s = getenv("ZPM_ROOT_DIR"))) {
1171 /* TODO does this need to be copied ? */
1176 * -d localdb or ZPMDB * or /var/lib/zpm/zpm.db, or die
1177 * -f 'package database', otherwise regular default of env
1178 * ZPM_PACKAGE_FILE, or use pkgdb if otherwise not found
1179 * -R root of pkg, will just chdir there
1181 * args are pkgid triple, but will do a pkg find on the pkgdb
1184 while ((opt = getopt(ac, av, "f:d:c:nCR:vOA")) != -1) {
1186 case 'd': localdbfile = optarg; break;
1187 case 'f': pkgdbfile = optarg; break;
1188 case 'n': conf.dryrun = 1; break;
1189 case 'v': conf.verbose++; break;
1190 case 'C': conf.errabort = 0; break;
1191 case 'R': conf.rootdir = optarg; break;
1192 case 'N': conf.setuser = 0; conf.setgroup = 0; break;
1193 case 'O': conf.overwrite = 1; break;
1194 case 'A': conf.absorb = 1; break;
1202 /* verify root dir exists */
1203 if (conf.rootdir && !exists(conf.rootdir, NULL)) {
1204 fprintf(stderr, "rootdir %s does not exist\n", conf.rootdir);
1207 if (!zpm_open(&localdb, localdbfile)) {
1208 fprintf(stderr, "can't open zpm db %s\n", localdbfile);
1211 conf.log = &localdb;
1214 if (!zpm_open(&pkgdb, pkgdbfile)) {
1215 fprintf(stderr, "can't open src db %s\n", localdbfile);
1222 /* TODO find pkgid from arg */
1224 /* TODO set conf var to finalize error reporting */
1226 fprintf(stderr, "syncing filesystem %s (ldb %s) from %s\n",
1227 conf.rootdir ? conf.rootdir : "/",
1228 localdbfile, pkgdbfile);
1232 conf.exitonerror = 0;
1233 check_conflicts(&conf, NULL, report_conflicts);
1235 if (conf.conflicts) {
1236 fprintf(stderr, "%d conflicts reported, aborting sync\n",
1240 /* no point in running it if we're just going to
1241 * overwrite everything
1243 if (!conf.overwrite && !conf.absorb && !conf.dryrun) {
1244 runstage(&conf, "new", check_existing);
1248 fprintf(stderr, "beginning %ssync\n", conf.dryrun ?
1251 /* have to do the removes first otherwise
1252 * old files may conflict with update file
1256 conf.exitonerror = conf.dryrun ? 0 : 1;
1257 conf.errabort = conf.dryrun ? 0 : 1;
1260 fprintf(stderr, "removing old files\n");
1262 runstage(&conf, "remove", remove_files);
1265 fprintf(stderr, "updating files\n");
1267 runstage(&conf, "update", install_files);
1269 fprintf(stderr, "installing files\n");
1271 runstage(&conf, "new", install_files);
1275 zpm_close(&localdb);
1276 zpm_close(conf.src);
1277 return conf.errors ? 1 : 0;