mirror of
https://github.com/jorgebucaran/fisher
synced 2024-08-17 12:31:05 +02:00
Add timeout argument and isolate $fisher_index.
This commit is contained in:
parent
14afdc31dc
commit
01af6b540d
2 changed files with 11 additions and 32 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue