Skip to content

Commit

Permalink
Sanity check automatic renaming of notes
Browse files Browse the repository at this point in the history
I got a report by Lukas Muehlethaler that he lost several notes while
using my notes.vim plug-in. The problem seems to be related to notes
with Unicode filenames. I've fortunately never had this happen to me and
I can't seem to reproduce his problem but if this really is a bug in my
plug-in it's a serious bug: The plug-in should never lose a single note!

I've now added a sanity check that makes sure the new note exists on
disk before the old note is deleted and if this fails a confirmation
dialog will pop up warning the user of the problem and asking them to
report the problem to me.
  • Loading branch information
xolox committed Jun 8, 2011
1 parent 6143437 commit a7a3d26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions autoload/xolox/notes.vim
Expand Up @@ -184,10 +184,22 @@ function! xolox#notes#save() abort " {{{1
let newpath = xolox#notes#title_to_fname(title)
if newpath == ''
echoerr "Invalid note title"
return
endif
let bang = v:cmdbang ? '!' : ''
execute 'saveas' bang fnameescape(newpath)
" XXX If {oldpath} and {newpath} end up pointing to the same file on disk
" yet xolox#misc#path#equals() doesn't catch this, we might end up
" deleting the user's one and only note! One way to circumvent this
" potential problem is to first delete the old note and then save the new
" note. The problem with this approach is that :saveas might fail in which
" case we've already deleted the old note...
if !xolox#misc#path#equals(oldpath, newpath)
if !filereadable(newpath)
let message = "The notes plug-in tried to rename your note but failed to create %s so won't delete %s or you could lose your note! This should never happen... If you don't mind me borrowing some of your time, please contact me at peter@peterodding.com and include the old and new filename so that I can try to reproduce the issue. Thanks!"
call confirm(printf(message, string(newpath), string(oldpath)))
return
endif
call delete(oldpath)
endif
call xolox#notes#cache_del(oldpath)
Expand Down
2 changes: 1 addition & 1 deletion plugin/notes.vim
Expand Up @@ -3,7 +3,7 @@
" Last Change: June 8, 2011
" URL: http://peterodding.com/code/vim/notes/
" License: MIT
" Version: 0.8.10
" Version: 0.8.11

" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3375 1 :AutoInstall: notes.zip
Expand Down

0 comments on commit a7a3d26

Please sign in to comment.