mirror of
https://github.com/Ascyii/vim-gnupg.git
synced 2026-01-01 14:24:25 -05:00
Handle rename() failures
Renaming the temporary, encrypted file to the intended filename (per the buffer) may fail (e.g., typoed directory name). In this case, remove the temporary file and then give the typical error message for this situation. In order to be safe, the message is manually being generated instead of trying to be clever and do something like “noautocmd write” expecting it to hit the same error that rename() did. Closes jamessan/vim-gnupg#56 Signed-off-by: James McCoy <vega.james@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
" Name: gnupg.vim
|
" Name: gnupg.vim
|
||||||
" Last Change: 2015 Dec 04
|
" Last Change: 2015 Dec 17
|
||||||
" Maintainer: James McCoy <vega.james@gmail.com>
|
" Maintainer: James McCoy <vega.james@gmail.com>
|
||||||
" Original Author: Markus Braun <markus.braun@krawel.de>
|
" Original Author: Markus Braun <markus.braun@krawel.de>
|
||||||
" Summary: Vim plugin for transparent editing of gpg encrypted files.
|
" Summary: Vim plugin for transparent editing of gpg encrypted files.
|
||||||
@@ -739,7 +739,15 @@ function s:GPGEncrypt()
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let filename = resolve(expand('<afile>'))
|
let filename = resolve(expand('<afile>'))
|
||||||
call rename(destfile, filename)
|
if rename(destfile, filename)
|
||||||
|
" Rename failed, so clean up the tempfile
|
||||||
|
call delete(destfile)
|
||||||
|
echohl GPGError
|
||||||
|
echom printf("\"%s\" E212: Can't open file for writing", filename)
|
||||||
|
echohl None
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
if auType == 'BufWrite'
|
if auType == 'BufWrite'
|
||||||
setl nomodified
|
setl nomodified
|
||||||
let &readonly = filereadable(filename) && filewritable(filename) == 0
|
let &readonly = filereadable(filename) && filewritable(filename) == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user