dedup

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

commit 4a9c691eb97725f224362ee65dc088f0260bc8b6
parent 6d6109301d421104c4d298b7d44914e45ad9e465
Author: sin <sin@2f30.org>
Date:   Wed, 21 Mar 2018 13:21:41 +0000

Fix bug

Diffstat:
Mdedup.c | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -148,8 +148,6 @@ hash_ent_add(unsigned char *md, uint64_t blkidx) memcpy(&hash_ent->cent.md, md, sizeof(hash_ent->cent.md)); hash_ent->cent.blkidx = blkidx; RB_INSERT(hash_tree, &hash_tree_head, hash_ent); - lseek(cfd, 0, SEEK_END); - xwrite(cfd, &hash_ent->cent, sizeof(hash_ent->cent)); return hash_ent; } @@ -266,10 +264,13 @@ dedup(int fd) ent = grow_ent(ent, ent->nblks + 1); if (lookup_blk(&blk, &blkidx) == -1) { + struct hash_ent *hash_ent; uint64_t nblks = storefile_nblks(); ent->blks[ent->nblks++] = nblks; - hash_ent_add(blk.md, nblks); + hash_ent = hash_ent_add(blk.md, nblks); + lseek(cfd, 0, SEEK_END); + xwrite(cfd, &hash_ent->cent, sizeof(hash_ent->cent)); append_blk(&blk); } else { ent->blks[ent->nblks++] = blkidx; @@ -338,10 +339,12 @@ rebuild_cache(void) nblks = storefile_nblks(); lseek(cfd, 0, SEEK_SET); for (i = 0; i < nblks; i++) { + struct hash_ent *hash_ent; struct blk blk; read_blk(&blk, i); - hash_ent_add(blk.md, i); + hash_ent = hash_ent_add(blk.md, i); + xwrite(cfd, &hash_ent->cent, sizeof(hash_ent->cent)); } } @@ -451,8 +454,9 @@ list(void) for (i = 0; i < enthdr.nents; i++) { struct ent ent; - if (xread(ifd, &ent, sizeof(ent)) == 0) + if (xread(ifd, &ent, sizeof(ent)) == 0) { errx(1, "unexpected EOF"); + } dump_md(ent.md, sizeof(ent.md)); putchar('\n'); lseek(ifd, ent.nblks * sizeof(ent.blks[0]), SEEK_CUR);