From 9924bf7ee22e2bf9adca378d7c8138d528dd3d1d Mon Sep 17 00:00:00 2001 From: Castulo Martinez Date: Tue, 9 Apr 2019 00:14:48 +0000 Subject: [PATCH] bundle-add installs optional bundles by default An optional bundle is not required to be installed in the system while included bundles are. Swupd will install optional bundles on bundle-add by default. Signed-off-by: Castulo Martinez --- Makefile.am | 1 + src/bundle.c | 10 +++++ .../bundleadd/add-include-optional.bats | 42 +++++++++++++++++++ test/functional/testlib.bash | 11 ++++- 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100755 test/functional/bundleadd/add-include-optional.bats diff --git a/Makefile.am b/Makefile.am index b8cfaa63..99b54260 100644 --- a/Makefile.am +++ b/Makefile.am @@ -175,6 +175,7 @@ BATS = \ test/functional/bundleadd/add-experimental.bats \ test/functional/bundleadd/add-fall-back-to-fullfile.bats \ test/functional/bundleadd/add-include.bats \ + test/functional/bundleadd/add-include-optional.bats \ test/functional/bundleadd/add-install-time.bats \ test/functional/bundleadd/add-json.bats \ test/functional/bundleadd/add-multiple.bats \ diff --git a/src/bundle.c b/src/bundle.c index aaddb86b..4d6f123c 100644 --- a/src/bundle.c +++ b/src/bundle.c @@ -728,6 +728,16 @@ int add_subscriptions(struct list *bundles, struct list **subs, struct manifest } ret |= r; /* merge in recursive call results */ } + + if (manifest->optional) { + int r = add_subscriptions(manifest->optional, subs, mom, find_all, recursion + 1); + if (r & add_sub_ERR) { + free_manifest(manifest); + goto out; + } + ret |= r; /* merge in recursive call results */ + } + free_manifest(manifest); if (!find_all && is_installed_bundle(bundle)) { diff --git a/test/functional/bundleadd/add-include-optional.bats b/test/functional/bundleadd/add-include-optional.bats new file mode 100755 index 00000000..ec9826c9 --- /dev/null +++ b/test/functional/bundleadd/add-include-optional.bats @@ -0,0 +1,42 @@ +#!/usr/bin/env bats + +# Author: Castulo Martinez +# Email: castulo.martinez@intel.com + +load "../testlib" + +test_setup() { + + create_test_environment "$TEST_NAME" + create_bundle -n test-bundle1 -f /foo/test-file1 "$TEST_NAME" + create_bundle -n test-bundle2 -f /bar/test-file2 "$TEST_NAME" + create_bundle -n test-bundle3 -f /baz/test-file3 "$TEST_NAME" + # add test-bundle2 as a dependency of test-bundle1 and test-bundle3 as optional + add_dependency_to_manifest "$WEBDIR"/10/Manifest.test-bundle1 test-bundle2 + add_dependency_to_manifest -o "$WEBDIR"/10/Manifest.test-bundle1 test-bundle3 + +} + +@test "ADD051: Adding a bundle that includes an optional bundle" { + + # An optional bundle is not required to be installed in the system while includes + # are. Swupd will install optional bundles on bundle-add unless specified otherwise + # by using the --skip--optional flag. + + run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle1" + + assert_status_is 0 + expected_output=$(cat <<-EOM + Starting download of remaining update content. This may take a while... + Finishing download of update content... + Installing bundle(s) files... + Calling post-update helper scripts. + Successfully installed 1 bundle + EOM + ) + assert_is_output "$expected_output" + assert_file_exists "$TARGETDIR"/foo/test-file1 + assert_file_exists "$TARGETDIR"/bar/test-file2 + assert_file_exists "$TARGETDIR"/baz/test-file3 + +} diff --git a/test/functional/testlib.bash b/test/functional/testlib.bash index b9dc1a8b..482fa130 100644 --- a/test/functional/testlib.bash +++ b/test/functional/testlib.bash @@ -868,7 +868,9 @@ add_to_manifest() { # swupd_function add_dependency_to_manifest() { # swupd_function local partial=false + local flag=includes [ "$1" = "-p" ] && { partial=true ; shift ; } + [ "$1" = "-o" ] && { flag=optional ; shift ; } local manifest=$1 local dependency=$2 local path @@ -879,13 +881,18 @@ add_dependency_to_manifest() { # swupd_function if [ $# -eq 0 ]; then cat <<-EOM Usage: - add_dependency_to_manifest + add_dependency_to_manifest [-p] [-o] Options: -p If set (partial), the dependency will be added to the manifest, but the manifest's tar won't be re-created, nor the hash in the MoM will be updated either. This is useful if more updates are to be done in the manifest to avoid extra processing + -o If set (optional), the dependency will be added to the manifest + as an optional dependency. + + Note: if both options -p and -o are to be used, they must be specified in that order or + one option will be ignored. EOM return fi @@ -910,7 +917,7 @@ add_dependency_to_manifest() { # swupd_function update_manifest -p "$manifest" previous "$pre_version" fi update_manifest -p "$manifest" timestamp "$(date +"%s")" - sudo sed -i "/^contentsize:.*/a includes:\\t$dependency" "$manifest" + sudo sed -i "/^contentsize:.*/a $flag:\\t$dependency" "$manifest" # If a manifest tar already exists for that manifest, renew the manifest tar # unless specified otherwise if [ "$partial" = false ]; then