Skip to content

Commit

Permalink
Use temp file to reduce risk of session file corruption
Browse files Browse the repository at this point in the history
Resolves: #71
  • Loading branch information
tpope committed Mar 25, 2022
1 parent a56dcd6 commit d2818a6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions plugin/obsession.vim
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,19 @@ function! s:persist() abort
if exists('g:this_obsession')
try
set sessionoptions-=blank sessionoptions-=options sessionoptions+=tabpages
let tmp = g:this_obsession . '.obsession.' . getpid()
exe s:doautocmd_user('ObsessionPre')
execute 'mksession! '.fnameescape(g:this_obsession)
let body = readfile(g:this_obsession)
execute 'mksession!' fnameescape(tmp)
let body = readfile(tmp)
call insert(body, 'let g:this_session = v:this_session', -3)
call insert(body, 'let g:this_obsession = v:this_session', -3)
if type(get(g:, 'obsession_append')) == type([])
for line in g:obsession_append
call insert(body, line, -3)
endfor
endif
call writefile(body, g:this_obsession)
call writefile(body, tmp)
call rename(tmp, g:this_obsession)
let g:this_session = g:this_obsession
exe s:doautocmd_user('Obsession')
catch /^Vim(mksession):E11:/
Expand Down

1 comment on commit d2818a6

@eph-raim
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.