dedup

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

commit 4e65a16a45c87ef2b43c2ce799091b74c475211a
parent 3609b47d0d3af4279f5b9988a92dd47c4a06a777
Author: sin <sin@2f30.org>
Date:   Wed, 27 Feb 2019 09:59:02 +0000

Fold rebuild_cache inside load_cache

There is a bug with rebuild cache at the moment.

Diffstat:
Mdedup.c | 28++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -428,23 +428,22 @@ flush_cache(struct cache_entry *cache_entry) return 0; } -static uint64_t -cache_nr_entries(void) +static void +load_cache(void) { struct stat sb; + uint64_t nr_entries; + uint64_t i; if (fstat(cfd, &sb) < 0) err(1, "fstat"); - return sb.st_size / CACHE_ENTRY_LEN; -} -static void -load_cache(void) -{ - uint64_t nr_entries; - uint64_t i; + nr_entries = sb.st_size / CACHE_ENTRY_LEN; + if (nr_entries == 0) { + walk_snap(rebuild_cache, NULL); + return; + } - nr_entries = cache_nr_entries(); for (i = 0; i < nr_entries; i++) { struct cache_entry cache_entry; @@ -479,6 +478,8 @@ load_snaphdr(void) static void init(void) { + cache = alloc_cache(); + ifd = open(SNAPSF, O_RDWR | O_CREAT, 0600); if (ifd < 0) err(1, "open %s", SNAPSF); @@ -497,12 +498,7 @@ init(void) errx(1, "busy lock"); load_snaphdr(); - - cache = alloc_cache(); - if (cache_nr_entries() != 0) - load_cache(); - else - walk_snap(rebuild_cache, NULL); + load_cache(); } static void