mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
patch 8.2.3218: when using xchaha20 crypt undo file is not removed
Problem: When using xchaha20 crypt undo file is not removed. Solution: Reset 'undofile' and delete the file. (Christian Brabandt, closes #8630, closes #8467)
This commit is contained in:
committed by
Bram Moolenaar
parent
3ed0d93796
commit
8a4c812ede
@@ -1982,8 +1982,6 @@ restore_backup:
|
|||||||
write_info.bw_start_lnum = start;
|
write_info.bw_start_lnum = start;
|
||||||
|
|
||||||
#ifdef FEAT_PERSISTENT_UNDO
|
#ifdef FEAT_PERSISTENT_UNDO
|
||||||
// TODO: if the selected crypt method prevents the undo file from being
|
|
||||||
// written, and existing undo file should be deleted.
|
|
||||||
write_undo_file = (buf->b_p_udf
|
write_undo_file = (buf->b_p_udf
|
||||||
&& overwriting
|
&& overwriting
|
||||||
&& !append
|
&& !append
|
||||||
@@ -1991,11 +1989,22 @@ restore_backup:
|
|||||||
# ifdef CRYPT_NOT_INPLACE
|
# ifdef CRYPT_NOT_INPLACE
|
||||||
// writing undo file requires
|
// writing undo file requires
|
||||||
// crypt_encode_inplace()
|
// crypt_encode_inplace()
|
||||||
&& (curbuf->b_cryptstate == NULL
|
&& (buf->b_cryptstate == NULL
|
||||||
|| crypt_works_inplace(curbuf->b_cryptstate))
|
|| crypt_works_inplace(buf->b_cryptstate))
|
||||||
# endif
|
# endif
|
||||||
&& reset_changed
|
&& reset_changed
|
||||||
&& !checking_conversion);
|
&& !checking_conversion);
|
||||||
|
# ifdef CRYPT_NOT_INPLACE
|
||||||
|
// remove undo file if encrypting it is not possible
|
||||||
|
if (buf->b_p_udf
|
||||||
|
&& overwriting
|
||||||
|
&& !append
|
||||||
|
&& !filtering
|
||||||
|
&& !checking_conversion
|
||||||
|
&& buf->b_cryptstate != NULL
|
||||||
|
&& !crypt_works_inplace(buf->b_cryptstate))
|
||||||
|
u_undofile_reset_and_delete(buf);
|
||||||
|
# endif
|
||||||
if (write_undo_file)
|
if (write_undo_file)
|
||||||
// Prepare for computing the hash value of the text.
|
// Prepare for computing the hash value of the text.
|
||||||
sha256_start(&sha_ctx);
|
sha256_start(&sha_ctx);
|
||||||
|
@@ -616,11 +616,8 @@ crypt_check_swapfile_curbuf(void)
|
|||||||
// swap and undo files, so disable them
|
// swap and undo files, so disable them
|
||||||
mf_close_file(curbuf, TRUE); // remove the swap file
|
mf_close_file(curbuf, TRUE); // remove the swap file
|
||||||
set_option_value((char_u *)"swf", 0, NULL, OPT_LOCAL);
|
set_option_value((char_u *)"swf", 0, NULL, OPT_LOCAL);
|
||||||
#ifdef FEAT_PERSISTENT_UNDO
|
|
||||||
set_option_value((char_u *)"udf", 0, NULL, OPT_LOCAL);
|
|
||||||
#endif
|
|
||||||
msg_scroll = TRUE;
|
msg_scroll = TRUE;
|
||||||
msg(_("Note: Encryption of swapfile not supported, disabling swap- and undofile"));
|
msg(_("Note: Encryption of swapfile not supported, disabling swap file"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -27,5 +27,6 @@ int anyBufIsChanged(void);
|
|||||||
int bufIsChangedNotTerm(buf_T *buf);
|
int bufIsChangedNotTerm(buf_T *buf);
|
||||||
int curbufIsChanged(void);
|
int curbufIsChanged(void);
|
||||||
void f_undofile(typval_T *argvars, typval_T *rettv);
|
void f_undofile(typval_T *argvars, typval_T *rettv);
|
||||||
|
void u_undofile_reset_and_delete(buf_T *buf);
|
||||||
void f_undotree(typval_T *argvars, typval_T *rettv);
|
void f_undotree(typval_T *argvars, typval_T *rettv);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
@@ -133,7 +133,7 @@ func Test_uncrypt_xchacha20_invalid()
|
|||||||
catch
|
catch
|
||||||
call assert_exception('pre-mature')
|
call assert_exception('pre-mature')
|
||||||
endtry
|
endtry
|
||||||
call assert_match("Note: Encryption of swapfile not supported, disabling swap- and undofile", execute(':5messages'))
|
call assert_match("Note: Encryption of swapfile not supported, disabling swap file", execute(':5messages'))
|
||||||
|
|
||||||
call assert_equal(0, &swapfile)
|
call assert_equal(0, &swapfile)
|
||||||
call assert_equal("xchacha20", &cryptmethod)
|
call assert_equal("xchacha20", &cryptmethod)
|
||||||
@@ -152,7 +152,7 @@ func Test_uncrypt_xchacha20_2()
|
|||||||
call feedkeys(":X\<CR>sodium\<CR>sodium\<CR>", 'xt')
|
call feedkeys(":X\<CR>sodium\<CR>sodium\<CR>", 'xt')
|
||||||
" swapfile disabled
|
" swapfile disabled
|
||||||
call assert_equal(0, &swapfile)
|
call assert_equal(0, &swapfile)
|
||||||
call assert_match("Note: Encryption of swapfile not supported, disabling swap- and undofile", execute(':messages'))
|
call assert_match("Note: Encryption of swapfile not supported, disabling swap file", execute(':messages'))
|
||||||
w!
|
w!
|
||||||
" encrypted using xchacha20
|
" encrypted using xchacha20
|
||||||
call assert_match("\[xchacha20\]", execute(':messages'))
|
call assert_match("\[xchacha20\]", execute(':messages'))
|
||||||
@@ -176,7 +176,7 @@ func Test_uncrypt_xchacha20_3_persistent_undo()
|
|||||||
sp Xcrypt_sodium_undo.txt
|
sp Xcrypt_sodium_undo.txt
|
||||||
set cryptmethod=xchacha20 undofile
|
set cryptmethod=xchacha20 undofile
|
||||||
call feedkeys(":X\<CR>sodium\<CR>sodium\<CR>", 'xt')
|
call feedkeys(":X\<CR>sodium\<CR>sodium\<CR>", 'xt')
|
||||||
call assert_equal(0, &undofile)
|
call assert_equal(1, &undofile)
|
||||||
let ufile=undofile(@%)
|
let ufile=undofile(@%)
|
||||||
call append(0, ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
|
call append(0, ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
|
||||||
call cursor(1, 1)
|
call cursor(1, 1)
|
||||||
@@ -189,6 +189,7 @@ func Test_uncrypt_xchacha20_3_persistent_undo()
|
|||||||
normal dd
|
normal dd
|
||||||
set undolevels=100
|
set undolevels=100
|
||||||
w!
|
w!
|
||||||
|
call assert_equal(0, &undofile)
|
||||||
bw!
|
bw!
|
||||||
call feedkeys(":sp Xcrypt_sodium_undo.txt\<CR>sodium\<CR>", 'xt')
|
call feedkeys(":sp Xcrypt_sodium_undo.txt\<CR>sodium\<CR>", 'xt')
|
||||||
" should fail
|
" should fail
|
||||||
|
22
src/undo.c
22
src/undo.c
@@ -3669,6 +3669,28 @@ f_undofile(typval_T *argvars UNUSED, typval_T *rettv)
|
|||||||
rettv->vval.v_string = NULL;
|
rettv->vval.v_string = NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#ifdef FEAT_PERSISTENT_UNDO
|
||||||
|
/*
|
||||||
|
* Reset undofile option and delete the undofile
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
u_undofile_reset_and_delete(buf_T *buf)
|
||||||
|
{
|
||||||
|
char_u *file_name;
|
||||||
|
|
||||||
|
if (!buf->b_p_udf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
file_name = u_get_undo_file_name(buf->b_ffname, TRUE);
|
||||||
|
if (file_name != NULL)
|
||||||
|
{
|
||||||
|
mch_remove(file_name);
|
||||||
|
vim_free(file_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_option_value((char_u *)"undofile", 0L, NULL, OPT_LOCAL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "undotree()" function
|
* "undotree()" function
|
||||||
|
@@ -755,6 +755,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3218,
|
||||||
/**/
|
/**/
|
||||||
3217,
|
3217,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user