mirror of
https://github.com/neovim/neovim.git
synced 2026-07-14 21:30:34 +00:00
vim-patch:8.1.0251: support full paths for 'backupdir' #11269
Problem: Using a full path is supported for 'directory' but not for
'backupdir'. (Mikolaj Machowski)
Solution: Support 'backupdir' as well. (Christian Brabandt, closes vim/vim#179)
b782ba475a
This commit is contained in:
committed by
Justin M. Keyes
parent
b1c4a8191e
commit
1ff5b60cb9
@@ -2650,6 +2650,7 @@ buf_write(
|
||||
*/
|
||||
if (!(append && *p_pm == NUL) && !filtering && perm >= 0 && dobackup) {
|
||||
FileInfo file_info;
|
||||
const bool no_prepend_dot = false;
|
||||
|
||||
if ((bkc & BKC_YES) || append) { /* "yes" */
|
||||
backup_copy = TRUE;
|
||||
@@ -2737,6 +2738,7 @@ buf_write(
|
||||
int some_error = false;
|
||||
char_u *dirp;
|
||||
char_u *rootname;
|
||||
char_u *p;
|
||||
|
||||
/*
|
||||
* Try to make the backup in each directory in the 'bdir' option.
|
||||
@@ -2756,6 +2758,17 @@ buf_write(
|
||||
* Isolate one directory name, using an entry in 'bdir'.
|
||||
*/
|
||||
(void)copy_option_part(&dirp, IObuff, IOSIZE, ",");
|
||||
p = IObuff + STRLEN(IObuff);
|
||||
if (after_pathsep((char *)IObuff, (char *)p) && p[-1] == p[-2]) {
|
||||
// Ends with '//', Use Full path
|
||||
if ((p = (char_u *)make_percent_swname((char *)IObuff, (char *)fname))
|
||||
!= NULL) {
|
||||
backup = (char_u *)modname((char *)p, (char *)backup_ext,
|
||||
no_prepend_dot);
|
||||
xfree(p);
|
||||
}
|
||||
}
|
||||
|
||||
rootname = get_file_in_dir(fname, IObuff);
|
||||
if (rootname == NULL) {
|
||||
some_error = TRUE; /* out of memory */
|
||||
@@ -2764,10 +2777,14 @@ buf_write(
|
||||
|
||||
FileInfo file_info_new;
|
||||
{
|
||||
/*
|
||||
* Make backup file name.
|
||||
*/
|
||||
backup = (char_u *)modname((char *)rootname, (char *)backup_ext, FALSE);
|
||||
//
|
||||
// Make the backup file name.
|
||||
//
|
||||
if (backup == NULL) {
|
||||
backup = (char_u *)modname((char *)rootname, (char *)backup_ext,
|
||||
no_prepend_dot);
|
||||
}
|
||||
|
||||
if (backup == NULL) {
|
||||
xfree(rootname);
|
||||
some_error = TRUE; /* out of memory */
|
||||
@@ -2893,12 +2910,26 @@ nobackup:
|
||||
* Isolate one directory name and make the backup file name.
|
||||
*/
|
||||
(void)copy_option_part(&dirp, IObuff, IOSIZE, ",");
|
||||
rootname = get_file_in_dir(fname, IObuff);
|
||||
if (rootname == NULL)
|
||||
backup = NULL;
|
||||
else {
|
||||
backup = (char_u *)modname((char *)rootname, (char *)backup_ext, FALSE);
|
||||
xfree(rootname);
|
||||
p = IObuff + STRLEN(IObuff);
|
||||
if (after_pathsep((char *)IObuff, (char *)p) && p[-1] == p[-2]) {
|
||||
// path ends with '//', use full path
|
||||
if ((p = (char_u *)make_percent_swname((char *)IObuff, (char *)fname))
|
||||
!= NULL) {
|
||||
backup = (char_u *)modname((char *)p, (char *)backup_ext,
|
||||
no_prepend_dot);
|
||||
xfree(p);
|
||||
}
|
||||
}
|
||||
|
||||
if (backup == NULL) {
|
||||
rootname = get_file_in_dir(fname, IObuff);
|
||||
if (rootname == NULL) {
|
||||
backup = NULL;
|
||||
} else {
|
||||
backup = (char_u *)modname((char *)rootname, (char *)backup_ext,
|
||||
no_prepend_dot);
|
||||
xfree(rootname);
|
||||
}
|
||||
}
|
||||
|
||||
if (backup != NULL) {
|
||||
|
||||
@@ -1437,7 +1437,7 @@ recover_names (
|
||||
* Append the full path to name with path separators made into percent
|
||||
* signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"")
|
||||
*/
|
||||
static char *make_percent_swname(const char *dir, char *name)
|
||||
char *make_percent_swname(const char *dir, char *name)
|
||||
FUNC_ATTR_NONNULL_ARG(1)
|
||||
{
|
||||
char *d = NULL;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
" This makes testing go faster, since Vim doesn't need to restart.
|
||||
|
||||
source test_assign.vim
|
||||
source test_backup.vim
|
||||
source test_behave.vim
|
||||
source test_cd.vim
|
||||
source test_changedtick.vim
|
||||
|
||||
58
src/nvim/testdir/test_backup.vim
Normal file
58
src/nvim/testdir/test_backup.vim
Normal file
@@ -0,0 +1,58 @@
|
||||
" Tests for the backup function
|
||||
|
||||
func Test_backup()
|
||||
set backup backupdir=.
|
||||
new
|
||||
call setline(1, ['line1', 'line2'])
|
||||
:f Xbackup.txt
|
||||
:w! Xbackup.txt
|
||||
" backup file is only created after
|
||||
" writing a second time (before overwriting)
|
||||
:w! Xbackup.txt
|
||||
let l = readfile('Xbackup.txt~')
|
||||
call assert_equal(['line1', 'line2'], l)
|
||||
bw!
|
||||
set backup&vim backupdir&vim
|
||||
call delete('Xbackup.txt')
|
||||
call delete('Xbackup.txt~')
|
||||
endfunc
|
||||
|
||||
func Test_backup2()
|
||||
set backup backupdir=.//
|
||||
new
|
||||
call setline(1, ['line1', 'line2', 'line3'])
|
||||
:f Xbackup.txt
|
||||
:w! Xbackup.txt
|
||||
" backup file is only created after
|
||||
" writing a second time (before overwriting)
|
||||
:w! Xbackup.txt
|
||||
sp *Xbackup.txt~
|
||||
call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
|
||||
let f=expand('%')
|
||||
call assert_match('src%nvim%testdir%Xbackup.txt\~', f)
|
||||
bw!
|
||||
bw!
|
||||
call delete('Xbackup.txt')
|
||||
call delete(f)
|
||||
set backup&vim backupdir&vim
|
||||
endfunc
|
||||
|
||||
func Test_backup2_backupcopy()
|
||||
set backup backupdir=.// backupcopy=yes
|
||||
new
|
||||
call setline(1, ['line1', 'line2', 'line3'])
|
||||
:f Xbackup.txt
|
||||
:w! Xbackup.txt
|
||||
" backup file is only created after
|
||||
" writing a second time (before overwriting)
|
||||
:w! Xbackup.txt
|
||||
sp *Xbackup.txt~
|
||||
call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
|
||||
let f=expand('%')
|
||||
call assert_match('src%nvim%testdir%Xbackup.txt\~', f)
|
||||
bw!
|
||||
bw!
|
||||
call delete('Xbackup.txt')
|
||||
call delete(f)
|
||||
set backup&vim backupdir&vim backupcopy&vim
|
||||
endfunc
|
||||
Reference in New Issue
Block a user