vim-patch:8.2.3543: swapname has double slash when 'directory' ends in it

Problem:    Swapname has double slash when 'directory' ends in double slash.
            (Shane Smith)
Solution:   Remove the superfluous slash. (closes vim/vim#8876)

8b0e62c93b

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2024-07-17 09:48:39 +08:00
parent dd61be59af
commit 4bb6cd4c2d
2 changed files with 6 additions and 7 deletions

View File

@@ -822,9 +822,6 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o
size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ","); size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ",");
char *p = IObuff + dir_len; char *p = IObuff + dir_len;
bool trailing_pathseps = after_pathsep(IObuff, p) && p[-1] == p[-2]; bool trailing_pathseps = after_pathsep(IObuff, p) && p[-1] == p[-2];
if (trailing_pathseps) {
IObuff[dir_len - 2] = NUL;
}
if (*dirp == NUL && !os_isdir(IObuff)) { if (*dirp == NUL && !os_isdir(IObuff)) {
int ret; int ret;
char *failed_dir; char *failed_dir;
@@ -964,9 +961,6 @@ nobackup:
size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ","); size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ",");
char *p = IObuff + dir_len; char *p = IObuff + dir_len;
bool trailing_pathseps = after_pathsep(IObuff, p) && p[-1] == p[-2]; bool trailing_pathseps = after_pathsep(IObuff, p) && p[-1] == p[-2];
if (trailing_pathseps) {
IObuff[dir_len - 2] = NUL;
}
if (*dirp == NUL && !os_isdir(IObuff)) { if (*dirp == NUL && !os_isdir(IObuff)) {
int ret; int ret;
char *failed_dir; char *failed_dir;

View File

@@ -1440,7 +1440,10 @@ int recover_names(char *fname, bool do_list, list_T *ret_list, int nr, char **fn
/// Append the full path to name with path separators made into percent /// Append the full path to name with path separators made into percent
/// signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"") /// signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"")
char *make_percent_swname(const char *dir, const char *name) /// signs, to "dir". An unnamed buffer is handled as "" (<currentdir>/"")
/// The last character in "dir" must be an extra slash or backslash, it is
/// removed.
char *make_percent_swname(char *dir, const char *name)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(1)
{ {
char *d = NULL; char *d = NULL;
@@ -1455,6 +1458,8 @@ char *make_percent_swname(const char *dir, const char *name)
*d = '%'; *d = '%';
} }
} }
dir[strlen(dir) - 1] = NUL; // remove one trailing slash
d = concat_fnames(dir, s, true); d = concat_fnames(dir, s, true);
xfree(s); xfree(s);
xfree(f); xfree(f);