X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-syncfs.c;h=3c0eebb0ff84bc43175d528f13e08c79e0514ce6;hb=556cd1f04308ff45196f9422f1568cdd493171a7;hp=d4fe2806eb9a3436764d2d1edc5a0c588cd6cc7c;hpb=a05f1728d09e6e17ca2b74c42052314cf88f7599;p=zpackage diff --git a/zpm-syncfs.c b/zpm-syncfs.c index d4fe280..3c0eebb 100644 --- a/zpm-syncfs.c +++ b/zpm-syncfs.c @@ -628,6 +628,20 @@ static int remove_files(void *f, int ncols, char **vals, char **cols) { 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) { @@ -646,19 +660,6 @@ static int remove_files(void *f, int ncols, char **vals, char **cols) { } /* TODO check that expected filetype matches actual filetype */ - 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; @@ -666,6 +667,10 @@ static int remove_files(void *f, int ncols, char **vals, char **cols) { switch (errno) { case ENOENT: break; + case ENOTEMPTY: /* fall through */ + case EEXIST: + /* TODO chatter, or possibly require */ + break; default: return seterror(conf, "can't unlink %s: %s", dest, strerror(errno)); } @@ -716,6 +721,17 @@ static int set_md(struct config *conf, struct nitem *item) { return success; } + if (conf->setuser && conf->setgroup) { + rv = lchown(item->dest, item->uid, item->gid); + if (rv == -1) { + setsyserr(conf, "can't lchown %s", item->dest); + return conf->errabort; + } + } + + /* have to chmod after the chown, setuid bits may (and will) + * be cleared after a chown + */ /* can't chmod a symlink */ if (item->ftype != 'l') { rv = chmod(item->dest, item->mode); @@ -726,13 +742,6 @@ static int set_md(struct config *conf, struct nitem *item) { } } - if (conf->setuser && conf->setgroup) { - rv = lchown(item->dest, item->uid, item->gid); - if (rv == -1) { - setsyserr(conf, "can't lchown %s", item->dest); - return conf->errabort; - } - } rv = utimensat(AT_FDCWD, item->dest, item->times, AT_SYMLINK_NOFOLLOW); if (rv == -1) { @@ -809,16 +818,11 @@ static int install(struct config *conf, struct nitem *item, unsigned int flags) } } - if (item->ftype == 'r') { - rv = zpm_extract(source, item->hash, item->dest, item->mode); - if (rv == 0) { - seterror(conf, "can't extract %s", item->dest); - return failure; - } - return success; - } - + errno = 0; switch (item->ftype) { + case 'r': rv = zpm_extract(source, item->hash, item->dest, item->mode); + if (rv == 0) rv = -1; + break; case 'd': rv = mkdir(item->dest, item->mode); break; case 'l': rv = symlink(item->target, item->dest); @@ -828,6 +832,17 @@ static int install(struct config *conf, struct nitem *item, unsigned int flags) } if (rv == -1) { + switch (item->ftype) { + case 'r': + seterror(conf, "can't extract %s", item->dest); + break; + case 'd': + setsyserr(conf, "install mkdir(\"%s\") failed", item->dest); + break; + case 'l': + setsyserr(conf, "install symlink(\"%s\") failed", item->dest); + break; + } setsyserr(conf, "installing %s failed", item->dest); return failure; }