dedup

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

commit e9be30a4e2a0583a262c06a70e676634a69eae3a
parent 9d31ed41e0feb2f2c432ef8d8666a6a0476c8f4f
Author: sin <sin@2f30.org>
Date:   Sun, 12 May 2019 16:47:49 +0100

snap.c: pack/unpack cannot fail

Diffstat:
Msnap.c | 25+++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/snap.c b/snap.c @@ -106,8 +106,7 @@ initmdhead(struct sctx *sctx) struct shdr *shdr; shdr = &sctx->shdr; - if (packshdr(ad, shdr) < 0) - return -1; + packshdr(ad, shdr); if (crypto_secretstream_xchacha20poly1305_init_pull(&state, shdr->header, @@ -232,13 +231,10 @@ screat(char *path, int mode, struct sctx **sctx) shdr->flags = (VMAJ << VMAJSHIFT) | VMIN; shdr->nbd = 0; - if (packshdr(buf, shdr) < 0) { + packshdr(buf, shdr); + if (xwrite(fd, buf, SHDRSIZE) != SHDRSIZE) { free(*sctx); close(fd); - return -1; - } - - if (xwrite(fd, buf, SHDRSIZE) != SHDRSIZE) { seterr("failed to write snapshot header: %s", strerror(errno)); return -1; } @@ -302,15 +298,12 @@ sopen(char *path, int flags, int mode, struct sctx **sctx) shdr = &(*sctx)->shdr; if (xread(fd, buf, SHDRSIZE) != SHDRSIZE) { - seterr("failed to read snapshot header: %s", strerror(errno)); - return -1; - } - - if (unpackshdr(buf, shdr) < 0) { free(sctx); close(fd); + seterr("failed to read snapshot header: %s", strerror(errno)); return -1; } + unpackshdr(buf, shdr); if (memcmp(shdr->magic, SHDRMAGIC, NSHDRMAGIC) != 0) { free(sctx); @@ -420,9 +413,7 @@ ssync(struct sctx *sctx) shdr->header, param.key); - if (packshdr(hdr, shdr) < 0) - return -1; - + packshdr(hdr, shdr); if (xwrite(sctx->fd, hdr, SHDRSIZE) != SHDRSIZE) { seterr("failed to write snapshot header: %s", strerror(errno)); return -1; @@ -450,9 +441,7 @@ ssync(struct sctx *sctx) } else { unsigned char hdr[SHDRSIZE]; - if (packshdr(hdr, shdr) < 0) - return -1; - + packshdr(hdr, shdr); if (xwrite(sctx->fd, hdr, SHDRSIZE) != SHDRSIZE) { seterr("failed to write snapshot header: %s", strerror(errno)); return -1;