@@ -3850,6 +3850,9 @@ buf_write(
38503850 stat_T st_new ;
38513851 char_u * dirp ;
38523852 char_u * rootname ;
3853+ #if defined(UNIX ) || defined(WIN3264 )
3854+ char_u * p ;
3855+ #endif
38533856#if defined(UNIX )
38543857 int did_set_shortname ;
38553858 mode_t umask_save ;
@@ -3887,6 +3890,17 @@ buf_write(
38873890 * Isolate one directory name, using an entry in 'bdir'.
38883891 */
38893892 (void )copy_option_part (& dirp , copybuf , BUFSIZE , "," );
3893+
3894+ #if defined(UNIX ) || defined(WIN3264 )
3895+ p = copybuf + STRLEN (copybuf );
3896+ if (after_pathsep (copybuf , p ) && p [-1 ] == p [-2 ])
3897+ // Ends with '//', use full path
3898+ if ((p = make_percent_swname (copybuf , fname )) != NULL )
3899+ {
3900+ backup = modname (p , backup_ext , FALSE);
3901+ vim_free (p );
3902+ }
3903+ #endif
38903904 rootname = get_file_in_dir (fname , copybuf );
38913905 if (rootname == NULL )
38923906 {
@@ -3904,9 +3918,10 @@ buf_write(
39043918 for (;;)
39053919 {
39063920 /*
3907- * Make backup file name.
3921+ * Make the backup file name.
39083922 */
3909- backup = buf_modname ((buf -> b_p_sn || buf -> b_shortname ),
3923+ if (backup == NULL )
3924+ backup = buf_modname ((buf -> b_p_sn || buf -> b_shortname ),
39103925 rootname , backup_ext , FALSE);
39113926 if (backup == NULL )
39123927 {
@@ -4108,14 +4123,29 @@ buf_write(
41084123 * Isolate one directory name and make the backup file name.
41094124 */
41104125 (void )copy_option_part (& dirp , IObuff , IOSIZE , "," );
4111- rootname = get_file_in_dir (fname , IObuff );
4112- if (rootname == NULL )
4113- backup = NULL ;
4114- else
4126+
4127+ #if defined(UNIX ) || defined(WIN3264 )
4128+ p = IObuff + STRLEN (IObuff );
4129+ if (after_pathsep (IObuff , p ) && p [-1 ] == p [-2 ])
4130+ // path ends with '//', use full path
4131+ if ((p = make_percent_swname (IObuff , fname )) != NULL )
4132+ {
4133+ backup = modname (p , backup_ext , FALSE);
4134+ vim_free (p );
4135+ }
4136+ #endif
4137+ if (backup == NULL )
41154138 {
4116- backup = buf_modname ((buf -> b_p_sn || buf -> b_shortname ),
4117- rootname , backup_ext , FALSE);
4118- vim_free (rootname );
4139+ rootname = get_file_in_dir (fname , IObuff );
4140+ if (rootname == NULL )
4141+ backup = NULL ;
4142+ else
4143+ {
4144+ backup = buf_modname (
4145+ (buf -> b_p_sn || buf -> b_shortname ),
4146+ rootname , backup_ext , FALSE);
4147+ vim_free (rootname );
4148+ }
41194149 }
41204150
41214151 if (backup != NULL )
@@ -6252,7 +6282,7 @@ shorten_filenames(char_u **fnames, int count)
62526282#endif
62536283
62546284/*
6255- * add extension to file name - change path/fo.o.h to path/fo.o.h.ext or
6285+ * Add extension to file name - change path/fo.o.h to path/fo.o.h.ext or
62566286 * fo_o_h.ext for MSDOS or when shortname option set.
62576287 *
62586288 * Assumed that fname is a valid name found in the filesystem we assure that
0 commit comments