Last active
November 13, 2015 08:57
-
-
Save Milly/264afb64e03857a10fb0 to your computer and use it in GitHub Desktop.
Fixed Vim `mch_FullName` in os_unix.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Makefile b/src/Makefile | |
index 90b2f0c..3139102 100644 | |
--- a/src/Makefile | |
+++ b/src/Makefile | |
@@ -1926,6 +1926,7 @@ test1 \ | |
test_options \ | |
test_perl \ | |
test_qf_title \ | |
+ test_resolve_swap \ | |
test_ruby \ | |
test_search_mbyte \ | |
test_set \ | |
diff --git a/src/os_unix.c b/src/os_unix.c | |
index 8f059be..4fb9cad 100644 | |
--- a/src/os_unix.c | |
+++ b/src/os_unix.c | |
@@ -2502,7 +2502,8 @@ mch_FullName(fname, buf, len, force) | |
#endif | |
/* expand it if forced or not an absolute path */ | |
- if (force || !mch_isFullName(fname)) | |
+ if ((force || !mch_isFullName(fname)) | |
+ && ((p = vim_strrchr(fname, '/')) == NULL || p != fname)) | |
{ | |
/* | |
* If the file name has a path, change to that directory for a moment, | |
diff --git a/src/testdir/Makefile b/src/testdir/Makefile | |
index 39d8388..1b9c69f 100644 | |
--- a/src/testdir/Makefile | |
+++ b/src/testdir/Makefile | |
@@ -59,6 +59,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \ | |
test_options.out \ | |
test_perl.out \ | |
test_qf_title.out \ | |
+ test_resolve_swap.out \ | |
test_ruby.out \ | |
test_search_mbyte.out \ | |
test_set.out \ | |
diff --git a/src/testdir/test_resolve_swap.in b/src/testdir/test_resolve_swap.in | |
new file mode 100644 | |
index 0000000..9b81897 | |
--- /dev/null | |
+++ b/src/testdir/test_resolve_swap.in | |
@@ -0,0 +1,59 @@ | |
+Tests for swap file detection. | |
+This test failed, if root '/' directory not writable. | |
+ | |
+STARTTEST | |
+:so small.vim | |
+:set nocompatible viminfo+=nviminfo | |
+:set dir=. | |
+:fun! TestSwap() | |
+: let dir = '/' | |
+: let fname = 'Xfile1' | |
+: let file = dir.fname | |
+: let fileswap = dir.'.'.fname.'.swp' | |
+: let link = 'Xlink1' | |
+: let linkswap = '.'.link.'.swp' | |
+: if !filewritable(dir) || glob(file) | |
+: " failed | |
+: return | |
+: endif | |
+: call writefile([], file) | |
+: exe '!ln -sfL' file link | |
+: exe 'e!' link | |
+: call append(0, 'test text swapfile') | |
+: preserve | |
+: exe '!ls' link '>>test.out' | |
+: exe '!ls' linkswap '>>test.out' | |
+: exe '!ls' file '>>test.out' | |
+: exe '!ls' fileswap '>>test.out' | |
+: set bin | |
+: exe 'sp' fileswap | |
+: w! /Xswap | |
+: set nobin | |
+: new | |
+: only! | |
+: exe 'bwipe!' link | |
+: exe 'bwipe!' file | |
+: exe 'bwipe!' fileswap | |
+: call delete(linkswap) | |
+: call delete(fileswap) | |
+: exe '!echo start not recovered file >>test.out' | |
+: exe '!cat' file '>>test.out' | |
+: exe '!echo end not recovered file >>test.out' | |
+: call rename('/Xswap', fileswap) | |
+: exe 'recover' link | |
+: w! | |
+: exe '!echo start recovered file >>test.out' | |
+: exe '!cat' file '>>test.out' | |
+: exe '!echo end recovered file >>test.out' | |
+: exe 'bwipe!' link | |
+: exe 'bwipe!' file | |
+: echo delete(fileswap) | |
+: echo delete(linkswap) | |
+: echo delete(link) | |
+: echo delete(file) | |
+:endfun | |
+:call writefile([], 'test.out') | |
+:call TestSwap() | |
+:qa! | |
+ENDTEST | |
+ | |
diff --git a/src/testdir/test_resolve_swap.ok b/src/testdir/test_resolve_swap.ok | |
new file mode 100644 | |
index 0000000..d832be8 | |
--- /dev/null | |
+++ b/src/testdir/test_resolve_swap.ok | |
@@ -0,0 +1,9 @@ | |
+Xlink1 | |
+/Xfile1 | |
+/.Xfile1.swp | |
+start not recovered file | |
+end not recovered file | |
+start recovered file | |
+test text swapfile | |
+ | |
+end recovered file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment