Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #65 from matthewrsj/contentsize-fix
Browse files Browse the repository at this point in the history
Calculate entire contentsize for manifest
  • Loading branch information
matthewrsj committed Aug 18, 2017
2 parents f9ec967 + 350bb54 commit e84600c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 15 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ TESTS = $(dist_check_SCRIPTS)

dist_check_SCRIPTS = \
test/functional/basic/test.bats \
test/functional/contentsize-across-versions-includes/test.bats \
test/functional/delete-no-version-bump/test.bats \
test/functional/file-name-blacklisted/test.bats \
test/functional/format-no-decrement/test.bats \
Expand Down
29 changes: 14 additions & 15 deletions src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,19 +675,29 @@ char *file_type_to_string(struct file *file)
return type;
}

/* Calculate the contentsize for the manifest based on file sizes.
*
* This should calculate the files uniquely included in this manifest, but none
* of its submanifests, which will allow calculation of sizes of all bundles on
* a system by adding all manifest->contentsizes of installed bundles.
*
* However, if two bundles not in the same include chain have overlapping
* content, summing the include chain of each bundle in the client will result
* in an over-estimation of the total size on the system. The more content is
* shared, the higher the over-estimation. In reality this overlap will not be
* large, but it is currently impossible to calculate the exact installed size
* using just the contentsize.
*/
static void compute_content_size(struct manifest *manifest)
{
/* FIXME: this is a temporary implementation based on worst case */

GList *list;
struct file *file;
struct manifest *submanifest;

list = g_list_first(manifest->files);
while (list) {
file = list->data;
list = g_list_next(list);
if (!file->is_deleted && (file->last_change == manifest->version)) {
if (!file->is_deleted) {
if (file->is_file) {
manifest->contentsize += file->stat.st_size;
} else if (file->is_link) {
Expand All @@ -697,17 +707,6 @@ static void compute_content_size(struct manifest *manifest)
}
}
}

list = g_list_first(manifest->submanifests);
while (list) {
submanifest = list->data;
list = g_list_next(list);

/* Do not take into account groups not included in download content */
if (create_download_content_for_group(submanifest->component)) {
manifest->contentsize += submanifest->contentsize;
}
}
}

/* Returns 0 == success, -1 == failure */
Expand Down
64 changes: 64 additions & 0 deletions test/functional/contentsize-across-versions-includes/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bats

# common functions
load "../swupdlib"

setup() {
clean_test_dir
init_test_dir

init_server_ini
init_groups_ini os-core test-bundle1 test-bundle2

set_os_release 10 os-core
track_bundle 10 os-core
track_bundle 10 test-bundle1
track_bundle 10 test-bundle2
gen_file_plain 10 test-bundle1 foo
gen_file_plain 10 test-bundle1 foobar
gen_file_plain 10 test-bundle2 foo2
gen_includes_file test-bundle2 10 test-bundle1

set_os_release 20 os-core
track_bundle 20 os-core
track_bundle 20 test-bundle1
track_bundle 20 test-bundle2
gen_file_plain 20 test-bundle1 foo
gen_file_plain 20 test-bundle1 foobar
gen_file_plain 20 test-bundle1 foobarbaz
gen_file_plain 20 test-bundle2 foo2
gen_file_plain 20 test-bundle2 foo2bar
gen_includes_file test-bundle2 20 test-bundle1
}

@test "correct contentsize" {
# create a couple updates to both check that contentsize does not add included
# bundles and to verify that files changed in previous updates are counted.
sudo $CREATE_UPDATE --osversion 10 --statedir $DIR --format 3
set_latest_ver 10

# contentsize for test-bundle2 should not include test-bundle1's contentsize
[[ 1 -eq $(grep '^contentsize: 11$' $DIR/www/10/Manifest.test-bundle1 | wc -l) ]]
[[ 1 -eq $(grep '^contentsize: 5$' $DIR/www/10/Manifest.test-bundle2 | wc -l) ]]
# os-core is large because it includes /usr/*
[[ 1 -eq $(grep '^contentsize: 5134$' $DIR/www/10/Manifest.os-core | wc -l) ]]
# 5134 + 11 + 5 = 5150
[[ 1 -eq $(grep '^contentsize: 5150$' $DIR/www/10/Manifest.full | wc -l) ]]

sudo $CREATE_UPDATE --osversion 20 --statedir $DIR --format 3
set_latest_ver 20

# one new file: foobarbaz (10 bytes)
[[ 1 -eq $(grep '^contentsize: 21$' $DIR/www/20/Manifest.test-bundle1 | wc -l) ]]
# one new file: foo2bar (8 bytes)
[[ 1 -eq $(grep '^contentsize: 13$' $DIR/www/20/Manifest.test-bundle2 | wc -l) ]]
# os-core should not change size
[[ 1 -eq $(grep '^contentsize: 5134$' $DIR/www/10/Manifest.os-core | wc -l) ]]
# contentsize for full should be all files, including ones not changed in this release
# two new files: foo2bar (8 bytes) and foobarbaz (10 bytes)
# 5150 + 10 + 8 = 5168
# 5134 + 21 + 13 = 5168
[[ 1 -eq $(grep '^contentsize: 5168$' $DIR/www/20/Manifest.full | wc -l) ]]
}

# vi: ft=sh ts=8 sw=2 sts=2 et tw=80

0 comments on commit e84600c

Please sign in to comment.