Handle script fetching errors

- make curl --fail on HTTP errors
- make curl -o output to file
- handle erros
- silence curl output
- unify curl command
This commit is contained in:
gmarik 2011-07-15 01:24:18 -05:00
parent 46d6ac3dfb
commit 2067c2fc62

View File

@ -60,24 +60,26 @@ func! s:display(headers, results)
endf endf
func! s:fetch_scripts(to) func! s:fetch_scripts(to)
let temp = shellescape(tempname()) let scripts_dir = fnamemodify(expand(a:to), ":h")
if has('win32') || has('win64') if !isdirectory(scripts_dir)
let scripts_dir = fnamemodify(expand(a:to), ":h") call mkdir(scripts_dir, "p")
if !isdirectory(scripts_dir)
call mkdir(scripts_dir, "p")
endif
exec '!curl http://vim-scripts.org/api/scripts.json > '.temp.
\ '&& move /Y '.temp.' '.shellescape(a:to)
else
exec '!curl http://vim-scripts.org/api/scripts.json > '.temp.
\ '&& mkdir -p $(dirname '.shellescape(a:to).') && mv -f '.temp.' '.shellescape(a:to)
endif endif
silent exec '!curl --fail -s -o '.shellescape(a:to).' http://vim-scripts.org/api/scripts.json'
if (0 != v:shell_error)
echoerr 'Error fetching scripts!'
return v:shell_error
endif
return 0
endf endf
func! s:load_scripts(bang) func! s:load_scripts(bang)
let f = expand('$HOME/.vim-vundle/vim-scripts.org.json') let f = expand('$HOME/.vim-vundle/vim-scripts.org.json')
if a:bang || !filereadable(f) if a:bang || !filereadable(f)
call s:fetch_scripts(f) if 0 != s:fetch_scripts(f)
return []
end
endif endif
return eval(readfile(f, 'b')[0]) return eval(readfile(f, 'b')[0])
endf endf