From b3c54d73af36bd9f34944f53a5b7500a8e3b87f1 Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Sat, 10 Feb 2024 01:47:06 -0500 Subject: [PATCH] common/xbps-src/shutils: add function for printing verbose messages --- common/xbps-src/shutils/common.sh | 6 +++++ common/xbps-src/shutils/update_check.sh | 33 +++++++++---------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh index 4083e08ee08..86d91fdf507 100644 --- a/common/xbps-src/shutils/common.sh +++ b/common/xbps-src/shutils/common.sh @@ -188,6 +188,12 @@ msg_normal() { fi } +msg_verbose() { + if [ -n "$XBPS_VERBOSE" ]; then + printf >&2 "$@" + fi +} + report_broken() { if [ "$show_problems" = "ignore-problems" ]; then return diff --git a/common/xbps-src/shutils/update_check.sh b/common/xbps-src/shutils/update_check.sh index 1dfd9207427..8bae017bbe4 100644 --- a/common/xbps-src/shutils/update_check.sh +++ b/common/xbps-src/shutils/update_check.sh @@ -8,19 +8,18 @@ update_check() { local urlpfx urlsfx local -A fetchedurls + # XBPS_UPDATE_CHECK_VERBOSE is the old way to show verbose messages + [ "$XBPS_UPDATE_CHECK_VERBOSE" ] && XBPS_VERBOSE="$XBPS_UPDATE_CHECK_VERBOSE" + if [ -r $update_override ]; then . $update_override - if [ "$XBPS_UPDATE_CHECK_VERBOSE" ]; then - echo "using $XBPS_TARGET_PKG/update overrides" 1>&2 - fi + msg_verbose "using $XBPS_TARGET_PKG/update overrides\n" if [ -n "$disabled" ]; then - echo "update-check DISABLED for $original_pkgname: $disabled" 1>&2 + msg_verbose "update-check DISABLED for $original_pkgname: $disabled\n" return 0 fi elif [ -z "$distfiles" ]; then - if [ "$XBPS_UPDATE_CHECK_VERBOSE" ]; then - echo "NO DISTFILES found for $original_pkgname" 1>&2 - fi + msg_verbose "NO DISTFILES found for $original_pkgname\n" return 0 fi @@ -94,9 +93,7 @@ update_check() { esac if [ "$rx" ]; then # substitute url if needed - if [ -n "$XBPS_UPDATE_CHECK_VERBOSE" ]; then - echo "(folder) fetching $urlpfx and scanning with $rx" 1>&2 - fi + msg_verbose "(folder) fetching $urlpfx and scanning with $rx\n" skipdirs= curl -A "xbps-src-update-check/$XBPS_SRC_VERSION" --max-time 10 -Lsk "$urlpfx" | grep -Po -i "$rx" | @@ -195,15 +192,11 @@ update_check() { rx=${rx:-'(?&2 - fi + msg_verbose "already fetched $url\n" continue fi - if [ -n "$XBPS_UPDATE_CHECK_VERBOSE" ]; then - echo "fetching $url and scanning with $rx" 1>&2 - fi + msg_verbose "fetching $url and scanning with $rx\n" curl -H 'Accept: text/html,application/xhtml+xml,application/xml,text/plain,application/rss+xml' -A "xbps-src-update-check/$XBPS_SRC_VERSION" --max-time 10 -Lsk "$url" | grep -Po -i "$rx" fetchedurls[$url]=yes @@ -214,9 +207,7 @@ update_check() { grep . || echo "NO VERSION found for $original_pkgname" 1>&2 } | while IFS= read -r found_version; do - if [ -n "$XBPS_UPDATE_CHECK_VERBOSE" ]; then - echo "found version $found_version" - fi + msg_verbose "found version $found_version\n" consider=true p="$ignore " while [ -n "$p" ]; do @@ -225,9 +216,7 @@ update_check() { case "$found_version" in $i) consider=false - if [ -n "$XBPS_UPDATE_CHECK_VERBOSE" ]; then - echo "ignored $found_version due to $i" - fi + msg_verbose "ignored $found_version due to $i\n" esac done if $consider; then