From bfb869816713ee2d635220b803cd8eb89f4cf444 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 8 Jun 2013 14:29:01 -0600 Subject: libreblacklist: fix a few bugs - set -e didn't work in blacklist-update when followed by || - it prompted before overwriting the local blacklist --- src/lib/conf.sh | 2 +- src/lib/libreblacklist | 7 +++---- test/lib-blacklist-test.sh | 49 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/lib/conf.sh b/src/lib/conf.sh index 67aeb96..840e908 100644 --- a/src/lib/conf.sh +++ b/src/lib/conf.sh @@ -93,7 +93,7 @@ load_files() { # Load the files for file in $(list_files $slug); do if [[ -r $file ]]; then - . "$file" + . "$file" || return 1 fi done diff --git a/src/lib/libreblacklist b/src/lib/libreblacklist index 5cfb410..fb8b43a 100755 --- a/src/lib/libreblacklist +++ b/src/lib/libreblacklist @@ -40,10 +40,9 @@ blacklist-cat() { # Usage: blacklist-update # Updates (or creates) the cached copy of the blacklist blacklist-update() ( - set -euE # allow it to not be set globally . libremessages - load_files libretools - check_vars libretools BLACKLIST + load_files libretools || return 1 + check_vars libretools BLACKLIST || return 1 local remote_blacklist="$BLACKLIST" local local_blacklist="$XDG_CACHE_HOME/libretools/blacklist.txt" @@ -53,7 +52,7 @@ blacklist-update() ( mkdir -p "${local_blacklist%/*}" if wget -N -q -O "${local_blacklist}.part" "$remote_blacklist" 2>/dev/null; then stat_done - mv "${local_blacklist}.part" "$local_blacklist" + mv -f "${local_blacklist}.part" "$local_blacklist" else stat_done rm "${local_blacklist}.part" diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh index 1432ff6..049a2a7 100644 --- a/test/lib-blacklist-test.sh +++ b/test/lib-blacklist-test.sh @@ -2,13 +2,14 @@ describe libreblacklist +. ./test-common.sh + before() { - tmpdir=$(mktemp -d --tmpdir test-libreblacklist.XXXXXXXXXXXX) - stat=0 + _before } after() { - rm -rf -- "$tmpdir" "$XDG_CACHE_HOME" "$XDG_CONFIG_HOME" + _after } it_works_with_just_pkgname() { @@ -66,6 +67,48 @@ it_fails_cat_when_there_is_no_blacklist_or_network() { [[ -n "$(cat $tmpdir/stderr)" ]] } +it_fails_update_when_BLACKLIST_is_unset() { + mkdir -p $XDG_CONFIG_HOME/libretools + echo "BLACKLIST=" >$XDG_CONFIG_HOME/libretools/libretools.conf + + libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat $tmpdir/stdout)" ]] + [[ -n "$(cat $tmpdir/stderr)" ]] +} + +it_fails_cat_when_syntax_error_in_conf() { + mkdir -p $XDG_CONFIG_HOME/libretools + # there is a stray single quote in there + echo "BLACKLIST='https://repo.parabolagnulinux.org/docs/blacklist.txt" >$XDG_CONFIG_HOME/libretools/libretools.conf + + libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat $tmpdir/stdout)" ]] + [[ -n "$(cat $tmpdir/stderr)" ]] +} + +it_downloads_the_blacklist_as_needed() { + require network || return 0 + mkdir -p $XDG_CONFIG_HOME/libretools + echo "BLACKLIST=https://repo.parabolagnulinux.org/docs/blacklist.txt" >$XDG_CONFIG_HOME/libretools/libretools.conf + + libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr + + [[ -n "$(cat $tmpdir/stdout)" ]] +} + +it_downloads_the_blacklist_repeatedly() { + require network || return 0 + mkdir -p $XDG_CONFIG_HOME/libretools + echo "BLACKLIST=https://repo.parabolagnulinux.org/docs/blacklist.txt" >$XDG_CONFIG_HOME/libretools/libretools.conf + + libreblacklist update + libreblacklist update +} + it_displays_help_and_fails_with_no_args() { libreblacklist >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? -- cgit v1.2.3-54-g00ecf