From 91566adbb2e245937978673410750d9960cb86b8 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 27 Jul 2019 21:34:28 +0200 Subject: Fix duplicate file accounting A file is a complete duplicate if: - It has no blocks, only a single fragment and that is a duplicate - It has blocks but no fragment and the blocks are duplicate - It has blocks and a fragment and both are duplicate The previous version only counted the last one. Signed-off-by: David Oberhollenzer --- lib/sqfs/statistics.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'lib/sqfs') diff --git a/lib/sqfs/statistics.c b/lib/sqfs/statistics.c index 2bd4acf..4452ad5 100644 --- a/lib/sqfs/statistics.c +++ b/lib/sqfs/statistics.c @@ -13,9 +13,11 @@ void sqfs_print_statistics(fstree_t *fs, sqfs_super_t *super) uint64_t output_bytes = 0; uint64_t input_bytes = 0; file_info_t *fi; + bool is_dupe; for (fi = fs->files; fi != NULL; fi = fi->next) { num_blocks = fi->size / fs->block_size; + is_dupe = true; if ((fi->size % fs->block_size) && !(fi->flags & FILE_FLAG_HAS_FRAGMENT)) { @@ -27,15 +29,13 @@ void sqfs_print_statistics(fstree_t *fs, sqfs_super_t *super) sparse += 1; } - if (fi->flags & FILE_FLAG_BLOCKS_ARE_DUPLICATE) { - duplicate_blocks += num_blocks - sparse; - } else { - blocks_written += num_blocks - sparse; - } - - if ((fi->flags & FILE_FLAG_FRAGMENT_IS_DUPLICATE) && - (fi->flags & FILE_FLAG_BLOCKS_ARE_DUPLICATE)) { - file_dup_count += 1; + if (num_blocks > sparse) { + if (fi->flags & FILE_FLAG_BLOCKS_ARE_DUPLICATE) { + duplicate_blocks += num_blocks - sparse; + } else { + blocks_written += num_blocks - sparse; + is_dupe = false; + } } if (fi->flags & FILE_FLAG_HAS_FRAGMENT) { @@ -43,9 +43,13 @@ void sqfs_print_statistics(fstree_t *fs, sqfs_super_t *super) frag_dup += 1; } else { frag_count += 1; + is_dupe = false; } } + if (is_dupe) + file_dup_count += 1; + sparse_blocks += sparse; file_count += 1; input_bytes += fi->size; -- cgit v1.2.3