aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/path.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2021-11-19 20:07:04 +0800
committerzeertzjq <zeertzjq@outlook.com>2021-11-19 20:07:04 +0800
commit0f58ba10e264697e4bb330a17b41cd9a0ceb8b1e (patch)
tree94b8fa70be765d992258217aad3f00d5cb35732c /src/nvim/path.c
parentf71be1f87b40bf863b6cf6b4fbcebffdd3297d88 (diff)
downloadrneovim-0f58ba10e264697e4bb330a17b41cd9a0ceb8b1e.tar.gz
rneovim-0f58ba10e264697e4bb330a17b41cd9a0ceb8b1e.tar.bz2
rneovim-0f58ba10e264697e4bb330a17b41cd9a0ceb8b1e.zip
vim-patch:8.2.3468: problem with :cd when editing file in non-existent directory
Problem: Problem with :cd when editing file in non-existent directory. (Yee Cheng Chin) Solution: Prepend the current directory to get the full path. (closes vim/vim#8903) https://github.com/vim/vim/commit/c6376c798433bcb9ee38a8664299d11454546950
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r--src/nvim/path.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c
index c28d848683..ffe7fb636f 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -2245,11 +2245,17 @@ int path_full_dir_name(char *directory, char *buffer, size_t len)
}
if (os_chdir(directory) != SUCCESS) {
- // Do not return immediately since we may be in the wrong directory.
- retval = FAIL;
- }
-
- if (retval == FAIL || os_dirname((char_u *)buffer, len) == FAIL) {
+ // Path does not exist (yet). For a full path fail,
+ // will use the path as-is. For a relative path use
+ // the current directory and append the file name.
+ if (path_is_absolute((const char_u *)directory)) {
+ // Do not return immediately since we may be in the wrong directory.
+ retval = FAIL;
+ } else {
+ xstrlcpy(buffer, old_dir, len);
+ append_path(buffer, directory, len);
+ }
+ } else if (os_dirname((char_u *)buffer, len) == FAIL) {
// Do not return immediately since we are in the wrong directory.
retval = FAIL;
}