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)
diff --git a/src/bufwrite.c b/src/bufwrite.c
index e480e57..a38fb1c 100644
--- a/src/bufwrite.c
+++ b/src/bufwrite.c
@@ -1982,8 +1982,6 @@
write_info.bw_start_lnum = start;
#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
&& overwriting
&& !append
@@ -1991,11 +1989,22 @@
# ifdef CRYPT_NOT_INPLACE
// writing undo file requires
// crypt_encode_inplace()
- && (curbuf->b_cryptstate == NULL
- || crypt_works_inplace(curbuf->b_cryptstate))
+ && (buf->b_cryptstate == NULL
+ || crypt_works_inplace(buf->b_cryptstate))
# endif
&& reset_changed
&& !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)
// Prepare for computing the hash value of the text.
sha256_start(&sha_ctx);