diff --git a/src/analyze/analyze-compare-versions.c b/src/analyze/analyze-compare-versions.c index 9545326fa9..9d9f7ed3cb 100644 --- a/src/analyze/analyze-compare-versions.c +++ b/src/analyze/analyze-compare-versions.c @@ -16,9 +16,9 @@ int verb_compare_versions(int argc, char *argv[], void *userdata) { if (argc == 3) { r = strverscmp_improved(ASSERT_PTR(argv[1]), ASSERT_PTR(argv[2])); printf("%s %s %s\n", - argv[1], - r < 0 ? "<" : r > 0 ? ">" : "==", - argv[2]); + isempty(argv[1]) ? "''" : argv[1], + comparison_operator(r), + isempty(argv[2]) ? "''" : argv[2]); /* This matches the exit convention used by rpmdev-vercmp. * We don't use named values because 11 and 12 don't have names. */ diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index 652667e330..cebb479e75 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -718,10 +718,13 @@ static int version_check(int fd_from, const char *from, int fd_to, const char *t to); r = compare_version(a, b); + log_debug("Comparing versions: \"%s\" %s \"%s", a, comparison_operator(r), b); if (r < 0) - return log_warning_errno(SYNTHETIC_ERRNO(ESTALE), "Skipping \"%s\", since newer boot loader version in place already.", to); - else if (r == 0) - return log_info_errno(SYNTHETIC_ERRNO(ESTALE), "Skipping \"%s\", since same boot loader version in place already.", to); + return log_warning_errno(SYNTHETIC_ERRNO(ESTALE), + "Skipping \"%s\", since newer boot loader version in place already.", to); + if (r == 0) + return log_info_errno(SYNTHETIC_ERRNO(ESTALE), + "Skipping \"%s\", since same boot loader version in place already.", to); return 0; } diff --git a/src/fundamental/string-util-fundamental.h b/src/fundamental/string-util-fundamental.h index 101c2ae1b6..01df4ce17a 100644 --- a/src/fundamental/string-util-fundamental.h +++ b/src/fundamental/string-util-fundamental.h @@ -76,6 +76,10 @@ static inline const sd_char *yes_no(sd_bool b) { return b ? STR_C("yes") : STR_C("no"); } +static inline const sd_char* comparison_operator(int result) { + return result < 0 ? STR_C("<") : result > 0 ? STR_C(">") : STR_C("=="); +} + sd_int strverscmp_improved(const sd_char *a, const sd_char *b); /* Like startswith(), but operates on arbitrary memory blocks */ diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 1054f9ea31..902d431d9a 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -835,7 +835,7 @@ static void test_strverscmp_improved_one(const char* a, const char *b, int expec log_info("'%s' %s '%s'%s", strnull(a), - r > 0 ? ">" : r < 0 ? "<" : "==", + comparison_operator(r), strnull(b), r == expected ? "" : " !!!!!!!!!!!!!"); assert_se(r == expected); diff --git a/test/test-compare-versions.sh b/test/test-compare-versions.sh index 6cfcc158e6..c40208be60 100755 --- a/test/test-compare-versions.sh +++ b/test/test-compare-versions.sh @@ -17,9 +17,10 @@ $ANALYZE compare-versions 1 '!=' 2 ( ! $ANALYZE compare-versions 1 gt 2 ) ( ! $ANALYZE compare-versions 1 '>' 2 ) -$ANALYZE compare-versions 1 2 | grep ' < ' -$ANALYZE compare-versions 2 2 | grep ' == ' -$ANALYZE compare-versions 2 1 | grep ' > ' +test "$($ANALYZE compare-versions 1 2)" = '1 < 2' +test "$($ANALYZE compare-versions 2 2)" = '2 == 2' +test "$($ANALYZE compare-versions 2 1)" = '2 > 1' +test "$($ANALYZE compare-versions '' '')" = "'' == ''" set +e