dedup

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

commit 481193d0d350c006ac751b4d36eb3a27baafb0a0
parent 0b82fde85e265955b50ed2a97109c2ca0af2b5ca
Author: sin <sin@2f30.org>
Date:   Thu, 16 May 2019 13:46:02 +0300

Make creat()/open() param handling the same

Diffstat:
Mbcompress.c | 23++++++++++++-----------
Mbencrypt.c | 29++++++++++++++---------------
2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/bcompress.c b/bcompress.c @@ -128,26 +128,27 @@ static int bcopen(struct bctx *bctx, char *path, int flags, int mode) { struct cctx *cctx; - - bctx->cctx = calloc(1, sizeof(struct cctx)); - if (bctx->cctx == NULL) { - seterr("calloc: %s", strerror(errno)); - return -1; - } - cctx = bctx->cctx; + int type; if (strcasecmp(param.calgo, "none") == 0) { - cctx->type = CDNONETYPE; + type = CDNONETYPE; } else if (strcasecmp(param.calgo, "snappy") == 0) { - cctx->type = CDSNAPPYTYPE; + type = CDSNAPPYTYPE; } else if (strcasecmp(param.calgo, "lz4") == 0) { - cctx->type = CDLZ4TYPE; + type = CDLZ4TYPE; } else { - free(cctx); seterr("invalid compression type: %s", param.calgo); return -1; } + bctx->cctx = calloc(1, sizeof(struct cctx)); + if (bctx->cctx == NULL) { + seterr("calloc: %s", strerror(errno)); + return -1; + } + cctx = bctx->cctx; + cctx->type = type; + if (bencryptops()->open(bctx, path, flags, mode) < 0) { free(cctx); return -1; diff --git a/bencrypt.c b/bencrypt.c @@ -141,32 +141,31 @@ static int beopen(struct bctx *bctx, char *path, int flags, int mode) { struct ectx *ectx; - - bctx->ectx = calloc(1, sizeof(struct ectx)); - if (bctx->ectx == NULL) { - seterr("calloc: %s", strerror(errno)); - return -1; - } - ectx = bctx->ectx; + int type; /* Determine algorithm type */ - if (strcasecmp(param.ealgo, "none") == 0) - ectx->type = EDNONETYPE; - else if (strcasecmp(param.ealgo, "XChaCha20-Poly1305") == 0) - ectx->type = EDCHACHATYPE; - else { - free(ectx); + if (strcasecmp(param.ealgo, "none") == 0) { + type = EDNONETYPE; + } else if (strcasecmp(param.ealgo, "XChaCha20-Poly1305") == 0) { + type = EDCHACHATYPE; + } else { seterr("invalid encryption type: %s", param.ealgo); return -1; } /* Ensure that if repo is encrypted, a key was provided */ - if (ectx->type != EDNONETYPE && !param.keyloaded) { - free(ectx); + if (type != EDNONETYPE && !param.keyloaded) { seterr("expected encryption key"); return -1; } + bctx->ectx = calloc(1, sizeof(struct ectx)); + if (bctx->ectx == NULL) { + seterr("calloc: %s", strerror(errno)); + return -1; + } + ectx = bctx->ectx; + ectx->type = type; memcpy(ectx->key, param.key, KEYSIZE); if (bstorageops()->open(bctx, path, flags, mode) < 0) {