dedup

deduplicating backup program
git clone git://git.2f30.org/dedup.git
Log | Files | Refs | README | LICENSE

commit 6650bc506d13a91f409788e350a48b38aaf5f98e
parent 4c5ae16edd863718cfffd011e983efd1946b4264
Author: sin <sin@2f30.org>
Date:   Fri,  3 May 2019 15:03:33 +0100

Use serr/berr in the tools

Diffstat:
Mdup-check.c | 18++++++++----------
Mdup-gc.c | 6+++---
Mdup-init.c | 4++--
Mdup-pack.c | 40+++++++++++++++++-----------------------
Mdup-rm.c | 20+++++++++-----------
Mdup-unpack.c | 32+++++++++++++-------------------
6 files changed, 52 insertions(+), 68 deletions(-)

diff --git a/dup-check.c b/dup-check.c @@ -17,7 +17,7 @@ int verbose; char *argv0; -static int +static void check(struct sctx *sctx, struct bctx *bctx) { unsigned char md[MDSIZE]; @@ -25,11 +25,10 @@ check(struct sctx *sctx, struct bctx *bctx) while ((n = sget(sctx, md)) == MDSIZE) { if (bcheck(bctx, md) < 0) - return -1; + berr("bcheck"); } if (n < 0) - return -1; - return 0; + serr("sget"); } static void @@ -91,17 +90,16 @@ main(int argc, char *argv[]) errx(1, "snprintf: %s: path too long", bpath); if (sopen(spath, S_READ, 0600, &sctx) < 0) - errx(1, "sopen: %s: failed", spath); + serr("sopen: %s", spath); if (bopen(bpath, B_READ, 0600, &bpar, &bctx) <0) - errx(1, "bopen: %s: failed", bpath); + berr("bopen: %s", bpath); - if (check(sctx, bctx) < 0) - errx(1, "check: failed"); + check(sctx, bctx); if (bclose(bctx) < 0) - errx(1, "bclose: failed"); + berr("bclose: %s", bpath); if (sclose(sctx) < 0) - errx(1, "sclose: failed"); + serr("sclose: %s", spath); return 0; } diff --git a/dup-gc.c b/dup-gc.c @@ -73,10 +73,10 @@ main(int argc, char *argv[]) err(1, "chdir: %s", repo); if (bopen(STORAGEPATH, B_RDWR, 0600, &bpar, &bctx) < 0) - errx(1, "bopen: failed"); + berr("bopen: %s", STORAGEPATH); if (bgc(bctx) < 0) - errx(1, "bgc: failed"); + berr("bgc: %s", STORAGEPATH); if (bclose(bctx) < 0) - errx(1, "bclose: failed"); + berr("bclose: %s", STORAGEPATH); return 0; } diff --git a/dup-init.c b/dup-init.c @@ -84,8 +84,8 @@ main(int argc, char *argv[]) mkdir(ARCHIVEPATH, 0700); if (bcreat(STORAGEPATH, 0600, &bpar, &bctx) < 0) - errx(1, "bcreat: failed"); + berr("bcreat: %s", STORAGEPATH); if (bclose(bctx) < 0) - errx(1, "bclose: failed"); + berr("bclose: %s", STORAGEPATH); return 0; } diff --git a/dup-pack.c b/dup-pack.c @@ -18,13 +18,13 @@ int verbose; char *argv0; -static int +static void pack(struct sctx *sctx, struct bctx *bctx) { struct chunker *c; if ((c = copen(0, BSIZEMIN, BSIZEMAX, HMASKBITS, WINSIZE)) == NULL) - return -1; + errx(1, "copen: failed"); while (cfill(c) > 0) { unsigned char md[MDSIZE]; @@ -32,22 +32,17 @@ pack(struct sctx *sctx, struct bctx *bctx) size_t n; buf = cget(c, &n); - if (bput(bctx, buf, n, md) < 0) { - cclose(c); - return -1; - } - - if (sput(sctx, md) < 0) { - cclose(c); - return -1; - } - - if (cdrain(c) < 0) { - cclose(c); - return -1; - } + if (buf == NULL) + errx(1, "cget: failed"); + if (bput(bctx, buf, n, md) < 0) + berr("bput"); + if (sput(sctx, md) < 0) + serr("sput"); + if (cdrain(c) < 0) + errx(1, "cdrain: failed"); } - return cclose(c); + if (cclose(c) < 0) + errx(1, "cclose: failed"); } static void @@ -109,16 +104,15 @@ main(int argc, char *argv[]) errx(1, "snprintf: %s: path too long", bpath); if (screat(spath, 0600, &sctx) < 0) - errx(1, "screat: %s: failed", spath); + serr("screat: %s", spath); if (bopen(bpath, B_RDWR, 0600, &bpar, &bctx) <0) - errx(1, "bopen: %s: failed", bpath); + berr("bopen: %s", bpath); - if (pack(sctx, bctx) < 0) - errx(1, "pack: failed"); + pack(sctx, bctx); if (bclose(bctx) < 0) - errx(1, "bclose: failed"); + berr("bclose: %s", bpath); if (sclose(sctx) < 0) - errx(1, "sclose: failed"); + serr("sclose: %s", spath); return 0; } diff --git a/dup-rm.c b/dup-rm.c @@ -17,7 +17,7 @@ int verbose; char *argv0; -static int +static void rm(struct sctx *sctx, struct bctx *bctx) { unsigned char md[MDSIZE]; @@ -25,11 +25,10 @@ rm(struct sctx *sctx, struct bctx *bctx) while ((n = sget(sctx, md)) == MDSIZE) { if (brm(bctx, md) < 0) - return -1; + berr("brm"); } if (n < 0) - return -1; - return 0; + serr("sget"); } static void @@ -91,20 +90,19 @@ main(int argc, char *argv[]) errx(1, "snprintf: %s: path too long", bpath); if (sopen(spath, S_READ, 0600, &sctx) < 0) - errx(1, "sopen: %s: failed", spath); + serr("sopen: %s", spath); if (bopen(bpath, B_RDWR, 0600, &bpar, &bctx) <0) - errx(1, "bopen: %s: failed", bpath); + berr("bopen: %s", bpath); - if (rm(sctx, bctx) < 0) - errx(1, "rm: failed"); + rm(sctx, bctx); if (bclose(bctx) < 0) - errx(1, "bclose: failed"); + berr("bclose: %s", bpath); if (sclose(sctx) < 0) - errx(1, "sclose: failed"); + serr("sclose: %s", spath); if (unlink(spath) < 0) - errx(1, "unlink: %s", spath); + err(1, "unlink: %s", spath); return 0; } diff --git a/dup-unpack.c b/dup-unpack.c @@ -19,7 +19,7 @@ extern ssize_t xwrite(int, void *, size_t); int verbose; char *argv0; -static int +static void unpack(struct sctx *sctx, struct bctx *bctx) { unsigned char md[MDSIZE]; @@ -28,23 +28,18 @@ unpack(struct sctx *sctx, struct bctx *bctx) buf = malloc(BSIZEMAX); if (buf == NULL) - return -1; + err(1, "malloc"); while ((sn = sget(sctx, md)) == MDSIZE) { size_t bn = BSIZEMAX; - if (bget(bctx, md, buf, &bn) < 0) { - free(buf); - return -1; - } - if (xwrite(1, buf, bn) != bn) { - free(buf); - return -1; - } + if (bget(bctx, md, buf, &bn) < 0) + berr("bget"); + if (xwrite(1, buf, bn) != bn) + err(1, "xwrite"); } - free(buf); if (sn < 0) - return -1; - return 0; + serr("sget"); + free(buf); } static void @@ -106,17 +101,16 @@ main(int argc, char *argv[]) errx(1, "snprintf: %s: path too long", bpath); if (sopen(spath, S_READ, 0600, &sctx) < 0) - errx(1, "sopen: %s: failed", spath); + serr("sopen: %s", spath); if (bopen(bpath, B_READ, 0600, &bpar, &bctx) <0) - errx(1, "bopen: %s: failed", bpath); + berr("bopen: %s", bpath); - if (unpack(sctx, bctx) < 0) - errx(1, "dedup: failed"); + unpack(sctx, bctx); if (bclose(bctx) < 0) - errx(1, "bclose: failed"); + berr("bclose: %s", bpath); if (sclose(sctx) < 0) - errx(1, "sclose: failed"); + serr("sclose: %s", spath); return 0; }