From ba74b99fd716b62e4073a1c23d62e0a3a4bc34de Mon Sep 17 00:00:00 2001 From: Chris Perl Date: Wed, 11 Jan 2012 10:55:39 -0500 Subject: [PATCH] Add s:Path.Resolve function to address trailing slash issues. The core issue is that in some versions of vim resolve() will remove trailing slashes, while in others it will not. This lead to commit bc745b6e99888c97c7e8f6ff3b7e8f605cab5af1 attempting to address a double slash problem. However, that broke symlink detection on systems where resolve() removes trailing slashes. This new function just calls vim's resolve() function, but removes trailing slashes if they exist. --- plugin/NERD_tree.vim | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 79302b8..7abafb0 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -2521,6 +2521,16 @@ function! s:Path.Slash() return s:running_windows ? '\' : '/' endfunction +"FUNCTION: Path.Resolve() {{{3 +"Invoke the vim resolve() function and return the result +"This is necessary because in some versions of vim resolve() removes trailing +"slashes while in other versions it doesn't. This always removes the trailing +"slash +function! s:Path.Resolve(path) + let tmp = resolve(a:path) + return tmp =~# '/$' ? substitute(tmp, '/$', '', '') : tmp +endfunction + "FUNCTION: Path.readInfoFromDisk(fullpath) {{{3 " " @@ -2555,12 +2565,12 @@ function! s:Path.readInfoFromDisk(fullpath) let lastPathComponent = self.getLastPathComponent(0) "get the path to the new node with the parent dir fully resolved - let hardPath = resolve(self.strTrunk()) . '/' . lastPathComponent + let hardPath = s:Path.Resolve(self.strTrunk()) . '/' . lastPathComponent "if the last part of the path is a symlink then flag it as such - let self.isSymLink = (resolve(hardPath) != hardPath) + let self.isSymLink = (s:Path.Resolve(hardPath) != hardPath) if self.isSymLink - let self.symLinkDest = resolve(fullpath) + let self.symLinkDest = s:Path.Resolve(fullpath) "if the link is a dir then slap a / on the end of its dest if isdirectory(self.symLinkDest) @@ -2971,7 +2981,7 @@ function! s:initNerdTree(name) if dir =~# '^\.' let dir = getcwd() . s:Path.Slash() . dir endif - let dir = resolve(dir) + let dir = s:Path.Resolve(dir) try let path = s:Path.New(dir)