Mercurial > vim
comparison src/memline.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 | 1c2d9f67d98f |
children | ef00b6bc186b |
comparison
equal
deleted
inserted
replaced
16737:e56018f01ba7 | 16738:b52ea9c5f1db |
---|---|
1082 } | 1082 } |
1083 | 1083 |
1084 | 1084 |
1085 /* | 1085 /* |
1086 * Try to recover curbuf from the .swp file. | 1086 * Try to recover curbuf from the .swp file. |
1087 * If "checkext" is TRUE, check the extension and detect whether it is | |
1088 * a swap file. | |
1087 */ | 1089 */ |
1088 void | 1090 void |
1089 ml_recover(void) | 1091 ml_recover(int checkext) |
1090 { | 1092 { |
1091 buf_T *buf = NULL; | 1093 buf_T *buf = NULL; |
1092 memfile_T *mfp = NULL; | 1094 memfile_T *mfp = NULL; |
1093 char_u *fname; | 1095 char_u *fname; |
1094 char_u *fname_used = NULL; | 1096 char_u *fname_used = NULL; |
1134 */ | 1136 */ |
1135 fname = curbuf->b_fname; | 1137 fname = curbuf->b_fname; |
1136 if (fname == NULL) /* When there is no file name */ | 1138 if (fname == NULL) /* When there is no file name */ |
1137 fname = (char_u *)""; | 1139 fname = (char_u *)""; |
1138 len = (int)STRLEN(fname); | 1140 len = (int)STRLEN(fname); |
1139 if (len >= 4 && | 1141 if (checkext && len >= 4 && |
1140 #if defined(VMS) | 1142 #if defined(VMS) |
1141 STRNICMP(fname + len - 4, "_s", 2) | 1143 STRNICMP(fname + len - 4, "_s", 2) |
1142 #else | 1144 #else |
1143 STRNICMP(fname + len - 4, ".s", 2) | 1145 STRNICMP(fname + len - 4, ".s", 2) |
1144 #endif | 1146 #endif |
1885 } | 1887 } |
1886 } | 1888 } |
1887 if (num_names == 0) | 1889 if (num_names == 0) |
1888 num_files = 0; | 1890 num_files = 0; |
1889 else if (expand_wildcards(num_names, names, &num_files, &files, | 1891 else if (expand_wildcards(num_names, names, &num_files, &files, |
1890 EW_KEEPALL|EW_FILE|EW_SILENT) == FAIL) | 1892 EW_NOTENV|EW_KEEPALL|EW_FILE|EW_SILENT) == FAIL) |
1891 num_files = 0; | 1893 num_files = 0; |
1892 | 1894 |
1893 /* | 1895 /* |
1894 * When no swap file found, wildcard expansion might have failed (e.g. | 1896 * When no swap file found, wildcard expansion might have failed (e.g. |
1895 * not able to execute the shell). | 1897 * not able to execute the shell). |
1928 */ | 1930 */ |
1929 if (curbuf->b_ml.ml_mfp != NULL | 1931 if (curbuf->b_ml.ml_mfp != NULL |
1930 && (p = curbuf->b_ml.ml_mfp->mf_fname) != NULL) | 1932 && (p = curbuf->b_ml.ml_mfp->mf_fname) != NULL) |
1931 { | 1933 { |
1932 for (i = 0; i < num_files; ++i) | 1934 for (i = 0; i < num_files; ++i) |
1933 if (fullpathcmp(p, files[i], TRUE) & FPC_SAME) | 1935 // Do not expand wildcards, on windows would try to expand |
1936 // "%tmp%" in "%tmp%file". | |
1937 if (fullpathcmp(p, files[i], TRUE, FALSE) & FPC_SAME) | |
1934 { | 1938 { |
1935 /* Remove the name from files[i]. Move further entries | 1939 // Remove the name from files[i]. Move further entries |
1936 * down. When the array becomes empty free it here, since | 1940 // down. When the array becomes empty free it here, since |
1937 * FreeWild() won't be called below. */ | 1941 // FreeWild() won't be called below. |
1938 vim_free(files[i]); | 1942 vim_free(files[i]); |
1939 if (--num_files == 0) | 1943 if (--num_files == 0) |
1940 vim_free(files); | 1944 vim_free(files); |
1941 else | 1945 else |
1942 for ( ; i < num_files; ++i) | 1946 for ( ; i < num_files; ++i) |