diff --git a/src/bundle.c b/src/bundle.c index 71134579..f4c4a78e 100644 --- a/src/bundle.c +++ b/src/bundle.c @@ -435,31 +435,45 @@ static void track_installed(const char *bundle_name) * user installed themselves just copy the entire system tracking directory * into the state tracking directory. */ if (!is_populated_dir(dst)) { - ret = mkdir(dst, S_IRWXU); + char *rmfile; + ret = rm_rf(dst); if (ret) { goto out; } - src = mk_full_filename(path_prefix, "/usr/share/clear/bundles/*"); + src = mk_full_filename(path_prefix, "/usr/share/clear/bundles"); /* at the point this function is called is already * installed on the system and therefore has a tracking file under * /usr/share/clear/bundles. A simple cp -a of that directory will * accurately track that bundle as manually installed. */ - ret = copy_all(src, dst); + ret = copy_all(src, state_dir); free_string(&src); if (ret) { goto out; } + /* remove uglies that live in the system tracking directory */ + rmfile = mk_full_filename(dst, ".MoM"); + (void)unlink(rmfile); + free_string(&rmfile); + /* set perms on the directory correctly */ + ret = chmod(dst, S_IRWXU); + if (ret) { + goto out; + } } char *tracking_file = mk_full_filename(dst, bundle_name); - int fd = open(tracking_file, O_RDWR | O_CREAT, S_IRUSR | S_IRGRP | S_IROTH); + int fd = open(tracking_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); free_string(&tracking_file); if (fd < 0) { + ret = -1; goto out; } close(fd); out: + if (ret) { + debug("Issue creating tracking file in %s for %s\n", dst, bundle_name); + } free_string(&dst); } diff --git a/test/functional/bundleadd/add-include.bats b/test/functional/bundleadd/add-include.bats index b697798d..ae7c5f97 100755 --- a/test/functional/bundleadd/add-include.bats +++ b/test/functional/bundleadd/add-include.bats @@ -7,6 +7,7 @@ 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 /bar/test-file3 "$TEST_NAME" # add test-bundle2 as a dependency of test-bundle1 add_dependency_to_manifest "$WEBDIR"/10/Manifest.test-bundle1 test-bundle2 @@ -14,11 +15,40 @@ test_setup() { @test "ADD013: Adding a bundle that includes another bundle" { + # Add bundle 3 to prime the bundles statedir contents so the tracked + # bundle detection can work in a realistic way + run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle3" run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle1" assert_status_is 0 assert_file_exists "$TARGETDIR"/foo/test-file1 assert_file_exists "$TARGETDIR"/bar/test-file2 + assert_file_exists "$STATEDIR"/bundles/test-bundle1 + assert_file_exists "$STATEDIR"/bundles/test-bundle3 + assert_file_not_exists "$STATEDIR"/bundles/test-bundle2 + 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" + +} + +@test "ADD048: Adding a bundle that includes another bundle (no tracking state)" { + + run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle1" + + assert_status_is 0 + assert_file_exists "$TARGETDIR"/foo/test-file1 + assert_file_exists "$TARGETDIR"/bar/test-file2 + assert_file_exists "$STATEDIR"/bundles/test-bundle1 + # When no tracking directly previously existed, all currently installed + # bundles are added to the tracked state. + assert_file_exists "$STATEDIR"/bundles/test-bundle2 expected_output=$(cat <<-EOM Starting download of remaining update content. This may take a while... Finishing download of update content... diff --git a/test/functional/bundleremove/remove-basics.bats b/test/functional/bundleremove/remove-basics.bats index abddf2ea..072404ac 100755 --- a/test/functional/bundleremove/remove-basics.bats +++ b/test/functional/bundleremove/remove-basics.bats @@ -5,8 +5,8 @@ load "../testlib" global_setup() { create_test_environment "$TEST_NAME" - create_bundle -L -n test-bundle1 -d /foo -f /test-file1,/bar/test-file2,/bat/test-file3,/bat/common "$TEST_NAME" - create_bundle -L -n test-bundle2 -f /bat/test-file4,/bat/common "$TEST_NAME" + create_bundle -L -t -n test-bundle1 -d /foo -f /test-file1,/bar/test-file2,/bat/test-file3,/bat/common "$TEST_NAME" + create_bundle -L -t -n test-bundle2 -f /bat/test-file4,/bat/common "$TEST_NAME" create_bundle -n test-bundle3 -f /baz/test-file5 "$TEST_NAME" } @@ -48,10 +48,12 @@ global_teardown() { assert_file_not_exists "$TARGETDIR"/bat/test-file3 assert_dir_not_exists "$TARGETDIR"/foo assert_dir_not_exists "$TARGETDIR"/bar + assert_file_not_exists "$STATEDIR"/bundles/test-bundle1 # bundle2 was not removed assert_file_exists "$TARGETDIR"/usr/share/clear/bundles/test-bundle2 assert_file_exists "$TARGETDIR"/bat/test-file4 assert_file_exists "$TARGETDIR"/bat/common + assert_file_exists "$STATEDIR"/bundles/test-bundle2 expected_output=$(cat <<-EOM Deleting bundle files... Total deleted files: 6 @@ -78,6 +80,8 @@ global_teardown() { assert_dir_not_exists "$TARGETDIR"/foo assert_dir_not_exists "$TARGETDIR"/bar assert_dir_not_exists "$TARGETDIR"/bat + assert_file_not_exists "$STATEDIR"/bundles/test-bundle1 + assert_file_not_exists "$STATEDIR"/bundles/test-bundle2 expected_output=$(cat <<-EOM Removing bundle: test-bundle1 Deleting bundle files... diff --git a/test/functional/testlib.bash b/test/functional/testlib.bash index 8a80d311..ede859ab 100644 --- a/test/functional/testlib.bash +++ b/test/functional/testlib.bash @@ -1837,10 +1837,11 @@ create_bundle() { # swupd_function cb_usage() { cat <<-EOM Usage: - create_bundle [-L] [-e] [-n] [-v] [-d] [-f] [-l] ENV_NAME + create_bundle [-L] [-t] [-e] [-n] [-v] [-d] [-f] [-l] ENV_NAME Options: -L When the flag is selected the bundle will be 'installed' in the target-dir, otherwise it will only be created in web-dir + -t The bundle will be 'tracked' in the state-dir regardless of if its content is installed on the system -e The bundle will be marked as experimental -n The name of the bundle to be created, if not specified a name will be autogenerated -v The version for the bundle, if non selected version 10 will be used @@ -1909,6 +1910,7 @@ create_bundle() { # swupd_function local manifest local local_bundle=false local experimental=false + local track_bundle=false local pfile local pfile_name local pfile_path @@ -1921,7 +1923,7 @@ create_bundle() { # swupd_function return fi set -f # turn off globbing - while getopts :v:d:f:l:b:c:n:Le opt; do + while getopts :v:d:f:l:b:c:n:tLe opt; do case "$opt" in d) IFS=, read -r -a dir_list <<< "$OPTARG" ;; f) IFS=, read -r -a file_list <<< "$OPTARG" ;; @@ -1930,6 +1932,7 @@ create_bundle() { # swupd_function c) IFS=, read -r -a dlink_list <<< "$OPTARG" ;; n) bundle_name="$OPTARG" ;; v) version="$OPTARG" ;; + t) track_bundle=true ;; L) local_bundle=true ;; e) experimental=true ;; *) cb_usage @@ -1956,6 +1959,7 @@ create_bundle() { # swupd_function version_path="$env_name"/web-dir/"$version" files_path="$version_path"/files target_path="$env_name"/testfs/target-dir + state_path="$env_name"/testfs/state # 1) create the initial manifest manifest=$(create_manifest "$version_path" "$bundle_name") @@ -2146,6 +2150,12 @@ create_bundle() { # swupd_function sudo touch "$target_path"/usr/share/clear/bundles/"$bundle_name" fi + # 10) Create the tracking file for the bundle if the track_bundle flag is set + if [ "$track_bundle" = true ]; then + sudo mkdir -p "$state_path"/bundles + sudo touch "$state_path"/bundles/"$bundle_name" + fi + } # Removes a bundle from the target-dir and/or the web-dir