From 080d805727091ca2bb7a1ae1e787342e821e890b Mon Sep 17 00:00:00 2001 From: William Douglas Date: Tue, 24 May 2016 16:51:54 +0000 Subject: [PATCH] Allow bundle-add to fallback to full files Instead of requiring a pack is used for bundle-add, allow the use of verify_fix_path when staging fails to: download, verify and stage the item using the full file. Correct output of tests where the 'required' wording was removed. --- Makefile.am | 1 + src/bundle.c | 35 +++++++++++----- .../bundleadd/add-directory/test.bats | 2 +- .../bundleadd/add-multiple/test.bats | 2 +- test/functional/bundleadd/boot-file/test.bats | 2 +- .../target-dir/usr/lib/os-release | 9 +++++ .../usr/share/clear/bundles/os-core | 0 .../bundleadd/fix-missing-file/test.bats | 40 +++++++++++++++++++ .../fix-missing-file/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 | 9 +++++ .../web-dir/10/Manifest.test-bundle.signed | 3 ++ ...bfdbdec784afef5a82ffa54e8c93bda3e0883360a3 | 1 + .../web-dir/version/formatstaging/latest | 1 + test/functional/bundleadd/include/test.bats | 2 +- .../bundleadd/verify-fix-path/test.bats | 2 +- 18 files changed, 116 insertions(+), 16 deletions(-) create mode 100644 test/functional/bundleadd/fix-missing-file/target-dir/usr/lib/os-release create mode 100644 test/functional/bundleadd/fix-missing-file/target-dir/usr/share/clear/bundles/os-core create mode 100755 test/functional/bundleadd/fix-missing-file/test.bats create mode 100644 test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.MoM create mode 100644 test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.MoM.signed create mode 100644 test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.os-core create mode 100644 test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.os-core.signed create mode 100644 test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.test-bundle create mode 100644 test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.test-bundle.signed create mode 100644 test/functional/bundleadd/fix-missing-file/web-dir/10/files/e6d85023c5e619eb43d5cfbfdbdec784afef5a82ffa54e8c93bda3e0883360a3 create mode 100644 test/functional/bundleadd/fix-missing-file/web-dir/version/formatstaging/latest diff --git a/Makefile.am b/Makefile.am index 4bdcbbff..bfc3c467 100644 --- a/Makefile.am +++ b/Makefile.am @@ -146,6 +146,7 @@ dist_check_SCRIPTS = \ test/functional/bundleadd/add-multiple/test.bats \ test/functional/bundleadd/boot-file/test.bats \ test/functional/bundleadd/include/test.bats \ + test/functional/bundleadd/fix-missing-file/test.bats \ test/functional/bundleadd/list/test.bats \ test/functional/bundleadd/verify-fix-path/test.bats \ test/functional/bundleremove/boot-file/test.bats \ diff --git a/src/bundle.c b/src/bundle.c index 77481b70..81173c1e 100644 --- a/src/bundle.c +++ b/src/bundle.c @@ -433,12 +433,8 @@ int install_bundles(struct list *bundles, int current_version, struct manifest * (void)rm_staging_dir_contents("download"); - printf("Downloading required packs...\n"); - ret = download_subscribed_packs(true); - if (ret != 0) { - printf("pack downloads failed, cannot proceed with the installation, exiting.\n"); - goto out; - } + printf("Downloading packs...\n"); + (void)download_subscribed_packs(true); /* step 3: Add tracked bundles */ read_subscriptions_alt(); @@ -466,15 +462,32 @@ int install_bundles(struct list *bundles, int current_version, struct manifest * } ret = do_staging(file, mom); - if (ret == 0) { - rename_staged_file_to_final(file); - } else { - printf("Failed to stage file: %s (ret = %d). Aborting bundle-add\n", - file->filename, ret); + if (ret) { + ret = verify_fix_path(file->filename, mom); + } + if (ret) { + ret = EBUNDLE_INSTALL; goto out; } } + iter = list_head(to_install_files); + while (iter) { + file = iter->data; + iter = iter->next; + + if (file->is_deleted || file->do_not_update || ignore(file)) { + continue; + } + + /* This was staged by verify_fix_path */ + if (!file->staging) { + file = search_file_in_manifest(mom, file->filename); + } + + rename_staged_file_to_final(file); + } + sync(); /* step 5: Run any scripts that are needed to complete update */ diff --git a/test/functional/bundleadd/add-directory/test.bats b/test/functional/bundleadd/add-directory/test.bats index 263c1b58..13e8dcef 100755 --- a/test/functional/bundleadd/add-directory/test.bats +++ b/test/functional/bundleadd/add-directory/test.bats @@ -26,7 +26,7 @@ teardown() { echo "$output" [ "${lines[2]}" = "Attempting to download version string to memory" ] - [ "${lines[3]}" = "Downloading required packs..." ] + [ "${lines[3]}" = "Downloading packs..." ] [ "${lines[4]}" = "Downloading test-bundle pack for version 10" ] [ "${lines[5]}" = "Extracting pack." ] [ "${lines[6]}" = "Installing bundle(s) files..." ] diff --git a/test/functional/bundleadd/add-multiple/test.bats b/test/functional/bundleadd/add-multiple/test.bats index 4faea3fc..bd59ce40 100755 --- a/test/functional/bundleadd/add-multiple/test.bats +++ b/test/functional/bundleadd/add-multiple/test.bats @@ -32,7 +32,7 @@ teardown() { echo "$output" [ "${lines[2]}" = "Attempting to download version string to memory" ] - [ "${lines[3]}" = "Downloading required packs..." ] + [ "${lines[3]}" = "Downloading packs..." ] [ "${lines[4]}" = "Downloading test-bundle1 pack for version 10" ] [ "${lines[5]}" = "Extracting pack." ] [ "${lines[6]}" = "Downloading test-bundle2 pack for version 10" ] diff --git a/test/functional/bundleadd/boot-file/test.bats b/test/functional/bundleadd/boot-file/test.bats index f8f99050..7c0f0720 100755 --- a/test/functional/bundleadd/boot-file/test.bats +++ b/test/functional/bundleadd/boot-file/test.bats @@ -26,7 +26,7 @@ teardown() { echo "$output" [ "${lines[2]}" = "Attempting to download version string to memory" ] - [ "${lines[3]}" = "Downloading required packs..." ] + [ "${lines[3]}" = "Downloading packs..." ] [ "${lines[4]}" = "Downloading test-bundle pack for version 10" ] [ "${lines[5]}" = "Extracting pack." ] [ "${lines[6]}" = "Installing bundle(s) files..." ] diff --git a/test/functional/bundleadd/fix-missing-file/target-dir/usr/lib/os-release b/test/functional/bundleadd/fix-missing-file/target-dir/usr/lib/os-release new file mode 100644 index 00000000..d20f3873 --- /dev/null +++ b/test/functional/bundleadd/fix-missing-file/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/bundleadd/fix-missing-file/target-dir/usr/share/clear/bundles/os-core b/test/functional/bundleadd/fix-missing-file/target-dir/usr/share/clear/bundles/os-core new file mode 100644 index 00000000..e69de29b diff --git a/test/functional/bundleadd/fix-missing-file/test.bats b/test/functional/bundleadd/fix-missing-file/test.bats new file mode 100755 index 00000000..d5298165 --- /dev/null +++ b/test/functional/bundleadd/fix-missing-file/test.bats @@ -0,0 +1,40 @@ +#!/usr/bin/env bats + +load "../../swupdlib" + +t1_hash="e6d85023c5e619eb43d5cfbfdbdec784afef5a82ffa54e8c93bda3e0883360a3" + +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 + sudo chown root:root "$DIR/web-dir/10/files/$t1_hash" + tar -C "$DIR/web-dir/10/files" -cf "$DIR/web-dir/10/files/$t1_hash.tar" $t1_hash --exclude=$t1_hash/* +} + +teardown() { + pushd "$DIR/web-dir/10" + rm *.tar + popd + pushd "$DIR/web-dir/10/files" + rm *.tar + popd + sudo chown $(ls -l "$DIR/test.bats" | awk '{ print $3 ":" $4 }') "$DIR/web-dir/10/files/$t1_hash" + sudo rm "$DIR/target-dir/foo" +} + +@test "bundle-add verify_fix_path support" { + run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle" + + echo "$output" + [ "${lines[2]}" = "Attempting to download version string to memory" ] + [ "${lines[3]}" = "Downloading packs..." ] + [ "${lines[4]}" = "Downloading test-bundle pack for version 10" ] + [ "${lines[5]}" = "Installing bundle(s) files..." ] + [ "${lines[6]}" = "Path /foo is missing on the file system" ] + [ "${lines[10]}" = "Bundle(s) installation done." ] + [ -f "$DIR/target-dir/foo" ] +} + +# vi: ft=sh ts=8 sw=2 sts=2 et tw=80 diff --git a/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.MoM b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.MoM new file mode 100644 index 00000000..96b2a8b4 --- /dev/null +++ b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.MoM @@ -0,0 +1,9 @@ +MANIFEST 3 +version: 10 +previous: 0 +filecount: 1 +timestamp: 1451940175 +contentsize: 13805671819 + +M... 6259043bcbac93ffff65097ec52ba0e8658e8b2b7cdb99bd2939d639ee23209e 10 os-core +M... 0259043bcbac93ffff65097ec52ba0e8658e8b2b7cdb99bd2939d639ee23209e 10 test-bundle diff --git a/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.MoM.signed b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.MoM.signed new file mode 100644 index 00000000..8b0f8fc5 --- /dev/null +++ b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.MoM.signed @@ -0,0 +1,3 @@ +-----BEGIN PKCS7----- +Empty +-----END PKCS7----- diff --git a/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.os-core b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.os-core new file mode 100644 index 00000000..410ebbfc --- /dev/null +++ b/test/functional/bundleadd/fix-missing-file/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/bundleadd/fix-missing-file/web-dir/10/Manifest.os-core.signed b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.os-core.signed new file mode 100644 index 00000000..8b0f8fc5 --- /dev/null +++ b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.os-core.signed @@ -0,0 +1,3 @@ +-----BEGIN PKCS7----- +Empty +-----END PKCS7----- diff --git a/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.test-bundle b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.test-bundle new file mode 100644 index 00000000..b0f21f40 --- /dev/null +++ b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.test-bundle @@ -0,0 +1,9 @@ +MANIFEST 3 +version: 10 +previous: 0 +filecount: 1 +timestamp: 1451936779 +contentsize: 17929151 +includes: os-core + +F... e6d85023c5e619eb43d5cfbfdbdec784afef5a82ffa54e8c93bda3e0883360a3 10 /foo diff --git a/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.test-bundle.signed b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.test-bundle.signed new file mode 100644 index 00000000..8b0f8fc5 --- /dev/null +++ b/test/functional/bundleadd/fix-missing-file/web-dir/10/Manifest.test-bundle.signed @@ -0,0 +1,3 @@ +-----BEGIN PKCS7----- +Empty +-----END PKCS7----- diff --git a/test/functional/bundleadd/fix-missing-file/web-dir/10/files/e6d85023c5e619eb43d5cfbfdbdec784afef5a82ffa54e8c93bda3e0883360a3 b/test/functional/bundleadd/fix-missing-file/web-dir/10/files/e6d85023c5e619eb43d5cfbfdbdec784afef5a82ffa54e8c93bda3e0883360a3 new file mode 100644 index 00000000..1304258b --- /dev/null +++ b/test/functional/bundleadd/fix-missing-file/web-dir/10/files/e6d85023c5e619eb43d5cfbfdbdec784afef5a82ffa54e8c93bda3e0883360a3 @@ -0,0 +1 @@ +test boot file diff --git a/test/functional/bundleadd/fix-missing-file/web-dir/version/formatstaging/latest b/test/functional/bundleadd/fix-missing-file/web-dir/version/formatstaging/latest new file mode 100644 index 00000000..f599e28b --- /dev/null +++ b/test/functional/bundleadd/fix-missing-file/web-dir/version/formatstaging/latest @@ -0,0 +1 @@ +10 diff --git a/test/functional/bundleadd/include/test.bats b/test/functional/bundleadd/include/test.bats index e3b5e7d2..e32c801f 100755 --- a/test/functional/bundleadd/include/test.bats +++ b/test/functional/bundleadd/include/test.bats @@ -31,7 +31,7 @@ teardown() { echo "$output" [ "${lines[2]}" = "Attempting to download version string to memory" ] - [ "${lines[3]}" = "Downloading required packs..." ] + [ "${lines[3]}" = "Downloading packs..." ] [ "${lines[4]}" = "Downloading test-bundle pack for version 10" ] [ "${lines[5]}" = "Extracting pack." ] [ "${lines[6]}" = "Downloading os-core pack for version 10" ] diff --git a/test/functional/bundleadd/verify-fix-path/test.bats b/test/functional/bundleadd/verify-fix-path/test.bats index 2bdbd4fb..5fe64f32 100755 --- a/test/functional/bundleadd/verify-fix-path/test.bats +++ b/test/functional/bundleadd/verify-fix-path/test.bats @@ -37,7 +37,7 @@ teardown() { echo "$output" [ "${lines[2]}" = "Attempting to download version string to memory" ] - [ "${lines[3]}" = "Downloading required packs..." ] + [ "${lines[3]}" = "Downloading packs..." ] [ "${lines[4]}" = "Downloading test-bundle pack for version 10" ] [ "${lines[5]}" = "Extracting pack." ] [ "${lines[6]}" = "Installing bundle(s) files..." ]