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())
if has('win32') || has('win64')
let scripts_dir = fnamemodify(expand(a:to), ":h") let scripts_dir = fnamemodify(expand(a:to), ":h")
if !isdirectory(scripts_dir) if !isdirectory(scripts_dir)
call mkdir(scripts_dir, "p") call mkdir(scripts_dir, "p")
endif endif
exec '!curl http://vim-scripts.org/api/scripts.json > '.temp.
\ '&& move /Y '.temp.' '.shellescape(a:to) silent exec '!curl --fail -s -o '.shellescape(a:to).' http://vim-scripts.org/api/scripts.json'
else
exec '!curl http://vim-scripts.org/api/scripts.json > '.temp. if (0 != v:shell_error)
\ '&& mkdir -p $(dirname '.shellescape(a:to).') && mv -f '.temp.' '.shellescape(a:to) echoerr 'Error fetching scripts!'
return v:shell_error
endif 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