diff --git a/Makefile.am b/Makefile.am index b7c6daf..a94c9f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -110,6 +110,7 @@ dist_check_SCRIPTS = \ test/functional/basic/test.bats \ test/functional/delete-no-version-bump/test.bats \ test/functional/file-name-blacklisted/test.bats \ + test/functional/format-no-decrement/test.bats \ test/functional/full-run-delta/test.bats \ test/functional/full-run/test.bats \ test/functional/fullfiles/test.bats \ diff --git a/src/create_update.c b/src/create_update.c index b86d037..137a932 100644 --- a/src/create_update.c +++ b/src/create_update.c @@ -340,6 +340,17 @@ int main(int argc, char **argv) /* Step 2: Make a manifest for the os-core set */ old_MoM = manifest_from_file(current_version, "MoM"); + + /* Verify that the new format is not older than the previous format. It + * never makes sense to decrease the format number for the next build. */ + if (format < old_MoM->format) { + LOG(NULL, "", "Current format (%llu) must be greater than or equal to previous format (%llu). Exiting", + format, old_MoM->format); + printf("Current format (%llu) must be greater than or equal to previous format (%llu). Exiting\n", + format, old_MoM->format); + goto exit; + } + new_MoM = alloc_manifest(newversion, "MoM"); old_core = manifest_from_file(manifest_subversion(old_MoM, "os-core"), "os-core"); new_core = sub_manifest_from_directory("os-core", newversion); diff --git a/test/functional/format-no-decrement/test.bats b/test/functional/format-no-decrement/test.bats new file mode 100755 index 0000000..ff69018 --- /dev/null +++ b/test/functional/format-no-decrement/test.bats @@ -0,0 +1,35 @@ +#!/usr/bin/env bats + +# common functions +load "../swupdlib" + +setup() { + clean_test_dir + init_test_dir + + init_server_ini + set_latest_ver 0 + init_groups_ini os-core + + set_os_release 10 os-core + track_bundle 10 os-core + set_os_release 20 os-core + track_bundle 20 os-core + + gen_file_plain 10 os-core foo + gen_file_plain 10 os-core bar + gen_file_plain 20 os-core foo + gen_file_plain 20 os-core baz +} + +@test "ensure format numbers cannot be decremented" { + sudo $CREATE_UPDATE --osversion 10 --statedir $DIR --format 3 + set_latest_ver 10 + + # Now, decrement the format number. Should result in an EXIT_FAILURE. + run sudo $CREATE_UPDATE --osversion 20 --statedir $DIR --format 2 + echo "$output" + [ $status -eq 1 ] +} + +# vi: ft=sh ts=8 sw=2 sts=2 et tw=80