From 4b522b352ae9c1ccddfe7a09540b15c93b03fa16 Mon Sep 17 00:00:00 2001 From: William Douglas Date: Thu, 2 Jun 2016 21:40:43 +0000 Subject: [PATCH] Skip verified unchanged files in update Instead of just checking if the versions have changed for a file to be updated, compare the current file's hash to updated file's expected hash and only queue files for update that are changed. --- Makefile.am | 1 + src/manifest.c | 12 +++++ .../skip-verified-fullfiles/target-dir/foo | 1 + .../target-dir/usr/lib/os-release | 9 ++++ .../usr/share/clear/bundles/os-core | 0 .../usr/share/clear/bundles/test-bundle | 0 .../update/skip-verified-fullfiles/test.bats | 51 +++++++++++++++++++ .../web-dir/10/Manifest.MoM | 9 ++++ .../web-dir/10/Manifest.MoM.signed | 3 ++ .../web-dir/10/Manifest.os-core | 8 +++ .../web-dir/10/Manifest.os-core.signed | 3 ++ .../web-dir/10/Manifest.test-bundle | 8 +++ .../web-dir/10/Manifest.test-bundle.signed | 3 ++ .../web-dir/100/Manifest.MoM | 9 ++++ .../web-dir/100/Manifest.MoM.signed | 3 ++ .../web-dir/100/Manifest.test-bundle | 8 +++ .../web-dir/100/Manifest.test-bundle.signed | 3 ++ .../web-dir/version/formatstaging/latest | 1 + 18 files changed, 132 insertions(+) create mode 100644 test/functional/update/skip-verified-fullfiles/target-dir/foo create mode 100644 test/functional/update/skip-verified-fullfiles/target-dir/usr/lib/os-release create mode 100644 test/functional/update/skip-verified-fullfiles/target-dir/usr/share/clear/bundles/os-core create mode 100644 test/functional/update/skip-verified-fullfiles/target-dir/usr/share/clear/bundles/test-bundle create mode 100755 test/functional/update/skip-verified-fullfiles/test.bats create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.MoM create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.MoM.signed create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.os-core create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.os-core.signed create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.test-bundle create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.test-bundle.signed create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.MoM create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.MoM.signed create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.test-bundle create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.test-bundle.signed create mode 100644 test/functional/update/skip-verified-fullfiles/web-dir/version/formatstaging/latest diff --git a/Makefile.am b/Makefile.am index bfc3c467..55dfbc57 100644 --- a/Makefile.am +++ b/Makefile.am @@ -174,6 +174,7 @@ dist_check_SCRIPTS = \ test/functional/update/include-old-bundle/test.bats \ test/functional/update/missing-os-core/test.bats \ test/functional/update/newest-deleted/test.bats \ + test/functional/update/skip-verified-fullfiles/test.bats \ test/functional/update/status/test.bats \ test/functional/update/status-no-server-content/test.bats \ test/functional/update/status-no-target-content/test.bats \ diff --git a/src/manifest.c b/src/manifest.c index f353cac5..e3e2b492 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -606,6 +606,7 @@ struct list *create_update_list(struct manifest *current, struct manifest *serve { struct list *output = NULL; struct list *list; + char *fullname = NULL; update_count = 0; update_skip = 0; @@ -615,6 +616,17 @@ struct list *create_update_list(struct manifest *current, struct manifest *serve file = list->data; list = list->next; + /* Skip files that aren't updated */ + fullname = mk_full_filename(path_prefix, file->filename); + if (fullname == NULL) { + abort(); + } + if (verify_file(file, fullname)) { + free(fullname); + continue; + } + free(fullname); + if ((file->last_change > current->version) || (file->is_rename && file_has_different_hash_in_older_manifest(current, file)) || !file->is_tracked) { diff --git a/test/functional/update/skip-verified-fullfiles/target-dir/foo b/test/functional/update/skip-verified-fullfiles/target-dir/foo new file mode 100644 index 00000000..257cc564 --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/target-dir/foo @@ -0,0 +1 @@ +foo diff --git a/test/functional/update/skip-verified-fullfiles/target-dir/usr/lib/os-release b/test/functional/update/skip-verified-fullfiles/target-dir/usr/lib/os-release new file mode 100644 index 00000000..d20f3873 --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/target-dir/usr/lib/os-release @@ -0,0 +1,9 @@ +NAME="Clear Linux Software for Intel Architecture" +VERSION=1 +ID=clear-linux-os +VERSION_ID=10 +PRETTY_NAME="Clear Linux Software for Intel Architecture" +ANSI_COLOR="1;35" +HOME_URL="https://clearlinux.org" +SUPPORT_URL="https://clearlinux.org" +BUG_REPORT_URL="https://bugs.clearlinux.org/jira" diff --git a/test/functional/update/skip-verified-fullfiles/target-dir/usr/share/clear/bundles/os-core b/test/functional/update/skip-verified-fullfiles/target-dir/usr/share/clear/bundles/os-core new file mode 100644 index 00000000..e69de29b diff --git a/test/functional/update/skip-verified-fullfiles/target-dir/usr/share/clear/bundles/test-bundle b/test/functional/update/skip-verified-fullfiles/target-dir/usr/share/clear/bundles/test-bundle new file mode 100644 index 00000000..e69de29b diff --git a/test/functional/update/skip-verified-fullfiles/test.bats b/test/functional/update/skip-verified-fullfiles/test.bats new file mode 100755 index 00000000..3b1ff7bd --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/test.bats @@ -0,0 +1,51 @@ +#!/usr/bin/env bats + +load "../../swupdlib" + +setup() { + clean_test_dir + tar -C "$DIR/web-dir/10" -cf "$DIR/web-dir/10/Manifest.MoM.tar" Manifest.MoM Manifest.MoM.signed + tar -C "$DIR/web-dir/10" -cf "$DIR/web-dir/10/Manifest.os-core.tar" Manifest.os-core Manifest.os-core.signed + tar -C "$DIR/web-dir/10" -cf "$DIR/web-dir/10/Manifest.test-bundle.tar" Manifest.test-bundle Manifest.test-bundle.signed + tar -C "$DIR/web-dir/100" -cf "$DIR/web-dir/100/Manifest.MoM.tar" Manifest.MoM Manifest.MoM.signed + tar -C "$DIR/web-dir/100" -cf "$DIR/web-dir/100/Manifest.test-bundle.tar" Manifest.test-bundle Manifest.test-bundle.signed + sudo chown root:root "$DIR/target-dir/foo" +} + +teardown() { + pushd "$DIR/web-dir/10" + rm *.tar + popd + pushd "$DIR/web-dir/100" + rm *.tar + popd + sudo chown $(ls -l "$DIR/test.bats" | awk '{ print $3 ":" $4 }') "$DIR/target-dir/foo" +} + +@test "update fullfile download skipped when hash verifies correctly" { + run sudo sh -c "$SWUPD update $SWUPD_OPTS" + + echo "$output" + [ "${lines[2]}" = "Attempting to download version string to memory" ] + [ "${lines[3]}" = "Update started." ] + [ "${lines[4]}" = "Querying server version." ] + [ "${lines[5]}" = "Attempting to download version string to memory" ] + [ "${lines[6]}" = "Preparing to update from 10 to 100" ] + [ "${lines[7]}" = "Querying current manifest." ] + [ "${lines[8]}" = "Querying server manifest." ] + [ "${lines[9]}" = "Downloading test-bundle pack for version 100" ] + [ "${lines[10]}" = "Statistics for going from version 10 to version 100:" ] + [ "${lines[11]}" = " changed manifests : 1" ] + [ "${lines[12]}" = " new manifests : 0" ] + [ "${lines[13]}" = " deleted manifests : 0" ] + [ "${lines[14]}" = " changed files : 0" ] + [ "${lines[15]}" = " new files : 0" ] + [ "${lines[16]}" = " deleted files : 0" ] + [ "${lines[17]}" = "Starting download of remaining update content. This may take a while..." ] + [ "${lines[18]}" = "Finishing download of update content..." ] + [ "${lines[19]}" = "Staging file content" ] + [ "${lines[20]}" = "Update was applied." ] + [ "${lines[24]}" = "Update successful. System updated from version 10 to version 100" ] +} + +# vi: ft=sh ts=8 sw=2 sts=2 et tw=80 diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.MoM b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.MoM new file mode 100644 index 00000000..346aabea --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.MoM @@ -0,0 +1,9 @@ +MANIFEST 3 +version: 10 +previous: 0 +filecount: 2 +timestamp: 1451940175 +contentsize: 13805671819 + +M... 9c2d6168821d121bbdfb4279f1ae04216f32ffac6bcad9e7349fc8642f162a93 10 os-core +M... e7457826b4c0bef114e29863347ecef2ec819f2a9193d96b1d1e516770974f54 10 test-bundle diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.MoM.signed b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.MoM.signed new file mode 100644 index 00000000..8b0f8fc5 --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.MoM.signed @@ -0,0 +1,3 @@ +-----BEGIN PKCS7----- +Empty +-----END PKCS7----- diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.os-core b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.os-core new file mode 100644 index 00000000..410ebbfc --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.os-core @@ -0,0 +1,8 @@ +MANIFEST 3 +version: 10 +previous: 0 +filecount: 1 +timestamp: 1451936779 +contentsize: 17929151 + +D... cde33514c151abb2b01448be290ab1d5212952571d15e3533cadc15ff82f2cd5 10 /usr diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.os-core.signed b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.os-core.signed new file mode 100644 index 00000000..8b0f8fc5 --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.os-core.signed @@ -0,0 +1,3 @@ +-----BEGIN PKCS7----- +Empty +-----END PKCS7----- diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.test-bundle b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.test-bundle new file mode 100644 index 00000000..d0c7bc52 --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.test-bundle @@ -0,0 +1,8 @@ +MANIFEST 3 +version: 10 +previous: 0 +filecount: 2 +timestamp: 1451936779 +contentsize: 17929151 + +F... 520f83440d3dddc25ad09ca858b9c669245f82d3181a45cdfe793aac9dd1fb15 10 /foo diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.test-bundle.signed b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.test-bundle.signed new file mode 100644 index 00000000..8b0f8fc5 --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/10/Manifest.test-bundle.signed @@ -0,0 +1,3 @@ +-----BEGIN PKCS7----- +Empty +-----END PKCS7----- diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.MoM b/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.MoM new file mode 100644 index 00000000..344307e3 --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.MoM @@ -0,0 +1,9 @@ +MANIFEST 3 +version: 100 +previous: 0 +filecount: 2 +timestamp: 1451940175 +contentsize: 13805671819 + +M... 9c2d6168821d121bbdfb4279f1ae04216f32ffac6bcad9e7349fc8642f162a93 10 os-core +M... 845ca4923f95159e424a5c6982088bae758f7735a8494f284bab24cb715ecfe3 100 test-bundle diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.MoM.signed b/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.MoM.signed new file mode 100644 index 00000000..8b0f8fc5 --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.MoM.signed @@ -0,0 +1,3 @@ +-----BEGIN PKCS7----- +Empty +-----END PKCS7----- diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.test-bundle b/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.test-bundle new file mode 100644 index 00000000..e40ee9aa --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.test-bundle @@ -0,0 +1,8 @@ +MANIFEST 3 +version: 100 +previous: 0 +filecount: 2 +timestamp: 1451936779 +contentsize: 17929151 + +F... 520f83440d3dddc25ad09ca858b9c669245f82d3181a45cdfe793aac9dd1fb15 100 /foo diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.test-bundle.signed b/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.test-bundle.signed new file mode 100644 index 00000000..8b0f8fc5 --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/100/Manifest.test-bundle.signed @@ -0,0 +1,3 @@ +-----BEGIN PKCS7----- +Empty +-----END PKCS7----- diff --git a/test/functional/update/skip-verified-fullfiles/web-dir/version/formatstaging/latest b/test/functional/update/skip-verified-fullfiles/web-dir/version/formatstaging/latest new file mode 100644 index 00000000..29d6383b --- /dev/null +++ b/test/functional/update/skip-verified-fullfiles/web-dir/version/formatstaging/latest @@ -0,0 +1 @@ +100