dedup

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

commit 42797a877f6efb89a46968af77fe8ab9c0e335fa
parent 921f7817b6057ac6d1efd12165e1593b0accfc4e
Author: sin <sin@2f30.org>
Date:   Sun,  5 May 2019 21:25:16 +0100

No need for a temporary bops pointer

Diffstat:
Mbcompress.c | 38++++++++++----------------------------
Mbencrypt.c | 40+++++++++++-----------------------------
2 files changed, 21 insertions(+), 57 deletions(-)

diff --git a/bcompress.c b/bcompress.c @@ -93,7 +93,6 @@ static int bccreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) { struct cctx *cctx; - struct bops *bops; int type; if (strcasecmp(bpar->calgo, "none") == 0) { @@ -115,8 +114,7 @@ bccreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) cctx = bctx->cctx; cctx->type = type; - bops = bencryptops(); - if (bops->creat(bctx, path, mode, bpar) < 0) { + if (bencryptops()->creat(bctx, path, mode, bpar) < 0) { free(cctx); return -1; } @@ -127,7 +125,6 @@ static int bcopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) { struct cctx *cctx; - struct bops *bops; bctx->cctx = calloc(1, sizeof(struct cctx)); if (bctx->cctx == NULL) { @@ -136,8 +133,7 @@ bcopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) } cctx = bctx->cctx; - bops = bencryptops(); - if (bops->open(bctx, path, flags, mode, bpar) < 0) { + if (bencryptops()->open(bctx, path, flags, mode, bpar) < 0) { free(cctx); return -1; } @@ -149,7 +145,7 @@ bcopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) } else if (strcasecmp(bpar->calgo, "lz4") == 0) { cctx->type = CDLZ4TYPE; } else { - bops->close(bctx); + bencryptops()->close(bctx); free(cctx); bseterr("invalid compression type: %s", bpar->calgo); return -1; @@ -161,7 +157,6 @@ static int bcput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) { struct cctx *cctx; - struct bops *bops; struct cd cd; char *cbuf; size_t cn; @@ -215,8 +210,7 @@ bcput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) cd.size = cn; packcd(cbuf, &cd); - bops = bencryptops(); - if (bops->put(bctx, cbuf, CDSIZE + cn, md) < 0) { + if (bencryptops()->put(bctx, cbuf, CDSIZE + cn, md) < 0) { free(cbuf); return -1; } @@ -228,7 +222,6 @@ bcput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) static int bcget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n) { - struct bops *bops; struct cd cd; char *cbuf; size_t cn, un, size; @@ -249,8 +242,7 @@ bcget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n) return -1; } - bops = bencryptops(); - if (bops->get(bctx, md, cbuf, &size) < 0) { + if (bencryptops()->get(bctx, md, cbuf, &size) < 0) { free(cbuf); return -1; } @@ -310,45 +302,35 @@ bcget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n) static int bcrm(struct bctx *bctx, unsigned char *md) { - struct bops *bops = bencryptops(); - - return bops->rm(bctx, md); + return bencryptops()->rm(bctx, md); } static int bcgc(struct bctx *bctx) { - struct bops *bops = bencryptops(); - - return bops->gc(bctx); + return bencryptops()->gc(bctx); } static int bccheck(struct bctx *bctx, unsigned char *md) { - struct bops *bops = bencryptops(); - - return bops->check(bctx, md); + return bencryptops()->check(bctx, md); } static int bcsync(struct bctx *bctx) { - struct bops *bops = bencryptops(); - - return bops->sync(bctx); + return bencryptops()->sync(bctx); } static int bcclose(struct bctx *bctx) { struct cctx *cctx = bctx->cctx; - struct bops *bops; free(cctx); - bops = bencryptops(); - return bops->close(bctx); + return bencryptops()->close(bctx); } struct bops * diff --git a/bencrypt.c b/bencrypt.c @@ -96,7 +96,6 @@ static int becreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) { struct ectx *ectx; - struct bops *bops; int type; /* Determine algorithm type */ @@ -130,8 +129,7 @@ becreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) if (bpar->key != NULL) memcpy(ectx->key, bpar->key, KEYSIZE); - bops = bstorageops(); - if (bops->creat(bctx, path, mode, bpar) < 0) { + if (bstorageops()->creat(bctx, path, mode, bpar) < 0) { free(ectx); return -1; } @@ -142,7 +140,6 @@ static int beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) { struct ectx *ectx; - struct bops *bops; bctx->ectx = calloc(1, sizeof(struct ectx)); if (bctx->ectx == NULL) { @@ -153,8 +150,7 @@ beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) if (bpar->key != NULL) memcpy(ectx->key, bpar->key, KEYSIZE); - bops = bstorageops(); - if (bops->open(bctx, path, flags, mode, bpar) < 0) { + if (bstorageops()->open(bctx, path, flags, mode, bpar) < 0) { free(ectx); return -1; } @@ -165,7 +161,7 @@ beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) else if (strcasecmp(bpar->ealgo, "XChaCha20-Poly1305") == 0) ectx->type = EDCHACHATYPE; else { - bops->close(bctx); + bstorageops()->close(bctx); free(ectx); bseterr("invalid encryption type: %s", bpar->ealgo); return -1; @@ -173,7 +169,7 @@ beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) /* Ensure that if repo is encrypted, a key was provided */ if (ectx->type != EDNONETYPE && bpar->key == NULL) { - bops->close(bctx); + bstorageops()->close(bctx); free(ectx); bseterr("expected encryption key"); return -1; @@ -186,7 +182,6 @@ static int beput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) { struct ectx *ectx; - struct bops *bops; struct ed ed; unsigned char *ebuf; size_t en; @@ -239,8 +234,7 @@ beput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) return -1; } - bops = bstorageops(); - if (bops->put(bctx, ebuf, EDSIZE + en, md) < 0) { + if (bstorageops()->put(bctx, ebuf, EDSIZE + en, md) < 0) { free(ebuf); return -1; } @@ -252,7 +246,6 @@ beput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) static int beget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n) { - struct bops *bops; struct ed ed; unsigned char *ebuf; size_t dn, size; @@ -266,8 +259,7 @@ beget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n) return -1; } - bops = bstorageops(); - if (bops->get(bctx, md, ebuf, &size) < 0) { + if (bstorageops()->get(bctx, md, ebuf, &size) < 0) { free(ebuf); return -1; } @@ -320,45 +312,35 @@ beget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n) static int berm(struct bctx *bctx, unsigned char *md) { - struct bops *bops = bstorageops(); - - return bops->rm(bctx, md); + return bstorageops()->rm(bctx, md); } static int begc(struct bctx *bctx) { - struct bops *bops = bstorageops(); - - return bops->gc(bctx); + return bstorageops()->gc(bctx); } static int becheck(struct bctx *bctx, unsigned char *md) { - struct bops *bops = bstorageops(); - - return bops->check(bctx, md); + return bstorageops()->check(bctx, md); } static int besync(struct bctx *bctx) { - struct bops *bops = bstorageops(); - - return bops->sync(bctx); + return bstorageops()->sync(bctx); } static int beclose(struct bctx *bctx) { struct ectx *ectx = bctx->ectx; - struct bops *bops; free(ectx); - bops = bstorageops(); - return bops->close(bctx); + return bstorageops()->close(bctx); } struct bops *