Factor out snapshot hash calculation to a function - dedup - deduplicating backup program
 (HTM) git clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 4122001dbfb14b263965c955e865a6c04151fbbc
 (DIR) parent 4106dd721d10db6f7ba0fe25009a85be8c5bee61
 (HTM) Author: sin <sin@2f30.org>
       Date:   Sun, 10 Mar 2019 10:25:26 +0000
       
       Factor out snapshot hash calculation to a function
       
       Diffstat:
         M dedup.c                             |      37 ++++++++++++++++++-------------
       
       1 file changed, 21 insertions(+), 16 deletions(-)
       ---
 (DIR) diff --git a/dedup.c b/dedup.c
       @@ -88,6 +88,26 @@ free_snap(struct snapshot *snap)
                free(snap);
        }
        
       +/*
       + * The snapshot hash is calculated over the
       + * hash of its block descriptors.
       + */
       +static void
       +hash_snap(struct snapshot *snap, uint8_t *md)
       +{
       +        SHA256_CTX ctx;
       +        uint64_t i;
       +
       +        SHA256_Init(&ctx);
       +        for (i = 0; i < snap->nr_blk_descs; i++) {
       +                struct blk_desc *blk_desc;
       +
       +                blk_desc = &snap->blk_desc[i];
       +                SHA256_Update(&ctx, blk_desc->md, sizeof(blk_desc->md));
       +        }
       +        SHA256_Final(md, &ctx);
       +}
       +
        static struct snapshot *
        grow_snap(struct snapshot *snap, uint64_t nr_blk_descs)
        {
       @@ -245,22 +265,7 @@ dedup(int fd, char *msg)
                }
        
                if (snap->nr_blk_descs > 0) {
       -                SHA256_CTX ctx;
       -                uint64_t i;
       -
       -                /*
       -                 * The snapshot hash is calculated over the
       -                 * hash of its block descriptors.
       -                 */
       -                SHA256_Init(&ctx);
       -                for (i = 0; i < snap->nr_blk_descs; i++) {
       -                        struct blk_desc *blk_desc;
       -
       -                        blk_desc = &snap->blk_desc[i];
       -                        SHA256_Update(&ctx, blk_desc->md,
       -                                      sizeof(blk_desc->md));
       -                }
       -                SHA256_Final(snap->md, &ctx);
       +                hash_snap(snap, snap->md);
        
                        if (msg != NULL) {
                                size_t size;