From 892a8771fa4b1693452929be771e0bf05d7b59b3 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Sun, 7 Feb 2016 20:08:08 +0900 Subject: [PATCH] Add timeout argument and isolate $fisher_index. --- functions/__fisher_index_update.fish | 22 +++++++++++----------- test/index-update.fish | 21 --------------------- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/functions/__fisher_index_update.fish b/functions/__fisher_index_update.fish index 3611bc0..481a93b 100644 --- a/functions/__fisher_index_update.fish +++ b/functions/__fisher_index_update.fish @@ -1,23 +1,23 @@ -function __fisher_index_update - set -l timeout 5 +function __fisher_index_update -a timeout + if test -z "$timeout" + set timeout 5 - if set -q fisher_timeout - set timeout "0$fisher_timeout" + if set -q fisher_timeout + set timeout "0$fisher_timeout" + end end + set -l url $fisher_index set -l index $fisher_cache/.index.tmp - # We pass a random query string after the URL to force the the - # server (GitHub) to always return the latest copy of the index. + if test -z "$url" - set -l query $fisher_index + # Force the server to return the latest copy of the index using a fake query string. - switch "$fisher_index" - case https://\* - set query $fisher_index\?(date +%s) + set url https://raw.githubusercontent.com/fisherman/fisher-index/master/index\?(date +%s) end - if not curl --max-time $timeout -sS "$query" > $index + if not curl --max-time $timeout -sS "$url" > $index rm -f $index return 1 end diff --git a/test/index-update.fish b/test/index-update.fish index 2ff2c1e..1795478 100644 --- a/test/index-update.fish +++ b/test/index-update.fish @@ -1,8 +1,3 @@ -# What is the difference between $fisher_index and $fisher_cache/.index? - -# The first one is a URL to a plain text file that lists all registered -# plugins and the second is a copy of that file. - set -l path $DIRNAME/.t-$TESTNAME-(random) function -S setup @@ -27,19 +22,3 @@ end test "$TESTNAME - Remove .tmp swap index file" ! -e $fisher_cache/.index.tmp end - -test "$TESTNAME - Return 1 if operation (curl) fails" - 1 -eq ( - set -e fisher_index - __fisher_index_update ^ /dev/null - echo $status - ) -end - -test "$TESTNAME - Original index is not modified in case of failure" - (seq 5) = ( - set -e fisher_index - __fisher_index_update ^ /dev/null - cat $fisher_cache/.index - ) -end