Mercurial > vim
comparison src/misc1.c @ 16738:b52ea9c5f1db v8.1.1371
patch 8.1.1371: cannot recover from a swap file
commit https://github.com/vim/vim/commit/99499b1c05f85f83876b828eea3f6e14f0f407b4
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu May 23 21:35:48 2019 +0200
patch 8.1.1371: cannot recover from a swap file
Problem: Cannot recover from a swap file.
Solution: Do not expand environment variables in the swap file name.
Do not check the extension when we already know a file is a swap
file. (Ken Takata, closes 4415, closes #4369)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 23 May 2019 21:45:07 +0200 |
parents | ba592f30c082 |
children | ef00b6bc186b |
comparison
equal
deleted
inserted
replaced
16737:e56018f01ba7 | 16738:b52ea9c5f1db |
---|---|
2689 * FPC_SAME if they both exist and are the same file. | 2689 * FPC_SAME if they both exist and are the same file. |
2690 * FPC_SAMEX if they both don't exist and have the same file name. | 2690 * FPC_SAMEX if they both don't exist and have the same file name. |
2691 * FPC_DIFF if they both exist and are different files. | 2691 * FPC_DIFF if they both exist and are different files. |
2692 * FPC_NOTX if they both don't exist. | 2692 * FPC_NOTX if they both don't exist. |
2693 * FPC_DIFFX if one of them doesn't exist. | 2693 * FPC_DIFFX if one of them doesn't exist. |
2694 * For the first name environment variables are expanded | 2694 * For the first name environment variables are expanded if "expandenv" is |
2695 * TRUE. | |
2695 */ | 2696 */ |
2696 int | 2697 int |
2697 fullpathcmp( | 2698 fullpathcmp( |
2698 char_u *s1, | 2699 char_u *s1, |
2699 char_u *s2, | 2700 char_u *s2, |
2700 int checkname) /* when both don't exist, check file names */ | 2701 int checkname, // when both don't exist, check file names |
2702 int expandenv) | |
2701 { | 2703 { |
2702 #ifdef UNIX | 2704 #ifdef UNIX |
2703 char_u exp1[MAXPATHL]; | 2705 char_u exp1[MAXPATHL]; |
2704 char_u full1[MAXPATHL]; | 2706 char_u full1[MAXPATHL]; |
2705 char_u full2[MAXPATHL]; | 2707 char_u full2[MAXPATHL]; |
2706 stat_T st1, st2; | 2708 stat_T st1, st2; |
2707 int r1, r2; | 2709 int r1, r2; |
2708 | 2710 |
2709 expand_env(s1, exp1, MAXPATHL); | 2711 if (expandenv) |
2712 expand_env(s1, exp1, MAXPATHL); | |
2713 else | |
2714 vim_strncpy(exp1, s1, MAXPATHL - 1); | |
2710 r1 = mch_stat((char *)exp1, &st1); | 2715 r1 = mch_stat((char *)exp1, &st1); |
2711 r2 = mch_stat((char *)s2, &st2); | 2716 r2 = mch_stat((char *)s2, &st2); |
2712 if (r1 != 0 && r2 != 0) | 2717 if (r1 != 0 && r2 != 0) |
2713 { | 2718 { |
2714 /* if mch_stat() doesn't work, may compare the names */ | 2719 /* if mch_stat() doesn't work, may compare the names */ |
2739 if ((exp1 = alloc(MAXPATHL * 3)) != NULL) | 2744 if ((exp1 = alloc(MAXPATHL * 3)) != NULL) |
2740 { | 2745 { |
2741 full1 = exp1 + MAXPATHL; | 2746 full1 = exp1 + MAXPATHL; |
2742 full2 = full1 + MAXPATHL; | 2747 full2 = full1 + MAXPATHL; |
2743 | 2748 |
2744 expand_env(s1, exp1, MAXPATHL); | 2749 if (expandenv) |
2750 expand_env(s1, exp1, MAXPATHL); | |
2751 else | |
2752 vim_strncpy(exp1, s1, MAXPATHL - 1); | |
2745 r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE); | 2753 r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE); |
2746 r2 = vim_FullName(s2, full2, MAXPATHL, FALSE); | 2754 r2 = vim_FullName(s2, full2, MAXPATHL, FALSE); |
2747 | 2755 |
2748 /* If vim_FullName() fails, the file probably doesn't exist. */ | 2756 /* If vim_FullName() fails, the file probably doesn't exist. */ |
2749 if (r1 != OK && r2 != OK) | 2757 if (r1 != OK && r2 != OK) |
4025 #endif | 4033 #endif |
4026 { | 4034 { |
4027 /* | 4035 /* |
4028 * First expand environment variables, "~/" and "~user/". | 4036 * First expand environment variables, "~/" and "~user/". |
4029 */ | 4037 */ |
4030 if (has_env_var(p) || *p == '~') | 4038 if ((has_env_var(p) && !(flags & EW_NOTENV)) || *p == '~') |
4031 { | 4039 { |
4032 p = expand_env_save_opt(p, TRUE); | 4040 p = expand_env_save_opt(p, TRUE); |
4033 if (p == NULL) | 4041 if (p == NULL) |
4034 p = pat[i]; | 4042 p = pat[i]; |
4035 #ifdef UNIX | 4043 #ifdef UNIX |