mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 15:08:35 +00:00
fix: remove trailing slashes before making directory
Remove the trailing slashes from 'undofile' and 'backupdir' before creating directories. They cause problems on Windows which doesn't recognize these slashes as proper path separators.
This commit is contained in:
@@ -2688,7 +2688,12 @@ buf_write(
|
|||||||
/*
|
/*
|
||||||
* Isolate one directory name, using an entry in 'bdir'.
|
* Isolate one directory name, using an entry in 'bdir'.
|
||||||
*/
|
*/
|
||||||
(void)copy_option_part(&dirp, IObuff, IOSIZE, ",");
|
size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ",");
|
||||||
|
p = IObuff + dir_len;
|
||||||
|
bool trailing_pathseps = after_pathsep((char *)IObuff, (char *)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;
|
||||||
@@ -2698,8 +2703,7 @@ buf_write(
|
|||||||
xfree(failed_dir);
|
xfree(failed_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p = IObuff + STRLEN(IObuff);
|
if (trailing_pathseps) {
|
||||||
if (after_pathsep((char *)IObuff, (char *)p) && p[-1] == p[-2]) {
|
|
||||||
// Ends with '//', Use Full path
|
// Ends with '//', Use Full path
|
||||||
if ((p = (char_u *)make_percent_swname((char *)IObuff, (char *)fname))
|
if ((p = (char_u *)make_percent_swname((char *)IObuff, (char *)fname))
|
||||||
!= NULL) {
|
!= NULL) {
|
||||||
@@ -2849,7 +2853,12 @@ nobackup:
|
|||||||
/*
|
/*
|
||||||
* Isolate one directory name and make the backup file name.
|
* Isolate one directory name and make the backup file name.
|
||||||
*/
|
*/
|
||||||
(void)copy_option_part(&dirp, IObuff, IOSIZE, ",");
|
size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ",");
|
||||||
|
p = IObuff + dir_len;
|
||||||
|
bool trailing_pathseps = after_pathsep((char *)IObuff, (char *)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;
|
||||||
@@ -2859,8 +2868,7 @@ nobackup:
|
|||||||
xfree(failed_dir);
|
xfree(failed_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p = IObuff + STRLEN(IObuff);
|
if (trailing_pathseps) {
|
||||||
if (after_pathsep((char *)IObuff, (char *)p) && p[-1] == p[-2]) {
|
|
||||||
// path ends with '//', use full path
|
// path ends with '//', use full path
|
||||||
if ((p = (char_u *)make_percent_swname((char *)IObuff, (char *)fname))
|
if ((p = (char_u *)make_percent_swname((char *)IObuff, (char *)fname))
|
||||||
!= NULL) {
|
!= NULL) {
|
||||||
|
@@ -1442,7 +1442,7 @@ recover_names (
|
|||||||
* 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, char *name)
|
char *make_percent_swname(const char *dir, const char *name)
|
||||||
FUNC_ATTR_NONNULL_ARG(1)
|
FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
char *d = NULL;
|
char *d = NULL;
|
||||||
|
@@ -672,6 +672,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading)
|
|||||||
#ifdef HAVE_READLINK
|
#ifdef HAVE_READLINK
|
||||||
char fname_buf[MAXPATHL];
|
char fname_buf[MAXPATHL];
|
||||||
#endif
|
#endif
|
||||||
|
char *p;
|
||||||
|
|
||||||
if (ffname == NULL) {
|
if (ffname == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -704,6 +705,13 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading)
|
|||||||
memmove(tail + tail_len + 1, ".un~", sizeof(".un~"));
|
memmove(tail + tail_len + 1, ".un~", sizeof(".un~"));
|
||||||
} else {
|
} else {
|
||||||
dir_name[dir_len] = NUL;
|
dir_name[dir_len] = NUL;
|
||||||
|
|
||||||
|
// Remove trailing pathseps from directory name
|
||||||
|
p = &dir_name[dir_len - 1];
|
||||||
|
while (vim_ispathsep(*p)) {
|
||||||
|
*p-- = NUL;
|
||||||
|
}
|
||||||
|
|
||||||
bool has_directory = os_isdir((char_u *)dir_name);
|
bool has_directory = os_isdir((char_u *)dir_name);
|
||||||
if (!has_directory && *dirp == NUL && !reading) {
|
if (!has_directory && *dirp == NUL && !reading) {
|
||||||
// Last directory in the list does not exist, create it.
|
// Last directory in the list does not exist, create it.
|
||||||
@@ -720,7 +728,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading)
|
|||||||
if (has_directory) {
|
if (has_directory) {
|
||||||
if (munged_name == NULL) {
|
if (munged_name == NULL) {
|
||||||
munged_name = xstrdup(ffname);
|
munged_name = xstrdup(ffname);
|
||||||
for (char *p = munged_name; *p != NUL; MB_PTR_ADV(p)) {
|
for (p = munged_name; *p != NUL; MB_PTR_ADV(p)) {
|
||||||
if (vim_ispathsep(*p)) {
|
if (vim_ispathsep(*p)) {
|
||||||
*p = '%';
|
*p = '%';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user