aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/fs.c
Commit message (Collapse)AuthorAge
* vim-patch:9.2.1169: getfsize() checks file type twice (#42261)zeertzjq14 days
| | | | | | | | | | | | | | | | Problem: getfsize() checks the file type twice. Solution: Use S_ISDIR macro instead of calling mch_isdir() (Yasuhiro Matsumoto). On MS-Windows: 40.8 us -> 26.6 us for a file, 41.1 us -> 25.3 us for a directory. closes: vim/vim#21448 Assisted-by: AI https://github.com/vim/vim/commit/ea1e40e5e06b1a6a5abebe77223f4a7e36930a87 Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
* vim-patch:8.2.1575: Vim9: globpath() doesnot take "true" as argumentJan Edmund Lazo2026-08-08
| | | | | | | | | Problem: Vim9: globpath() doesnot take "true" as argument. Solution: Use tv_get_bool_chk(). (closes vim/vim#6821) https://github.com/vim/vim/commit/f966ce5ea24748eed10f708d4f828be44887a559 Co-authored-by: Bram Moolenaar <Bram@vim.org>
* vim-patch:8.2.1574: Vim9: glob() doesnot take "true" as argumentJan Edmund Lazo2026-08-08
| | | | | | | | | Problem: Vim9: glob() doesnot take "true" as argument. Solution: Use tv_get_bool_chk(). (closes vim/vim#6821) https://github.com/vim/vim/commit/5892ea151197c8a6363c7ce2322d84277b97353e Co-authored-by: Bram Moolenaar <Bram@vim.org>
* refactor(path): pathcmp() #41035tao2026-08-07
| | | | | | | | | | | | | | | | | | | | | | Problem: Redudant code Solution: Add `path_fold_char()` to normalize path sep. Refactor `pathcmp()` and `path_fnamencmp()` into `path_cmp`. | feature | pathcmp | path_fnamencmp | path_cmp(now) | | ------------------------ | -------------- | -------------- | ------------- | | case folding | `mb_toupper()` | `utf_fold()` | `utf_fold()` | | consults fileignorecase | ✅ | ✅ | `ic` param | | `maxlen` | ✅ | ✅ | ✅ | | `/` == `\` | ✅ | ✅ | ✅ | | MSWIN drive letter | ❌ | ✅ | ✅ | | sep affects sorting | ✅ | ❌ | ✅ | | ignores a trailing slash | ✅ | ❌ | ✅ | Refactor `path_fnamecmp` and `path_full_compare` into `path_equal`, with flags controlling "no filesystem" comparison (i.e. `path_cmp`), env variables expansion, absolute path resolution and filesystem access.
* feat(cwd)!: :lcd! (bang), rearrange :bcd/:lcd/… scope precedence #41194Justin M. Keyes2026-08-07
| | | | | | | | | | | | | | | | Problem: - buf-local CWD scope is lower priority than :lcd, which is weird. ``` win > buf > tab > global ``` - No way to clear current CWD at a given scope. Solution: - Rerrange scope precedence to: ``` buf > win > tab > global ``` - Introduce "bang" variants (`:bcd!`/`:lcd!`/`:tcd!`) which clears the local CWD for the given scope.
* feat(cwd): support explicit chdir (:bcd/:tcd/…) in temp contextJustin M. Keyes2026-08-06
| | | | | | | | | | | | | | | | | | Problem: - Explicit `:bcd` (etc.) persists from `nvim_buf_call()` but not from an autocmd handler targeting a hidden buf (`LspAttach`, `TermRequest`, …), which needs a `vim.schedule()` workaround. - `vim._with()` is supposed to work as a "sandbox", discarding side-effects, but it leaks CWD changes: `:lcd` from a `win` context, any chdir from a visible-buffer context. Solution: - Explicit :cd/:tcd/:bcd during a temp context persists by default. - "Ambient" directory changes ('autochdir', existing win-local CWD, etc.) are still undone, as before. - Add `kCtxKeepDirs`: snapshot/restore the target's full CWD state (w/b/tp-local, global, cwd). Used by `vim._with()` and `'inccommand'`, which must not leak state.
* fix(cwd): validate getcwd(…, -1)Justin M. Keyes2026-08-04
|
* refactor(editor): cleanup change-directory (:bcd) logicJustin M. Keyes2026-08-04
|
* feat(editor): `:bcd` changes buffer-local directorysaher2026-08-04
| | | | | | | | | | | | | | | | | | Problem: No way to set a buffer-local directory. Use-cases: - "Root dir" for LSP (and the "project" concept). - `:terminal` OSC 7 Solution: Add `:bcd` command. - Extend `getcwd()` to take a third arg; `getcwd(-1, -1, bunfr)` returns the buffer-local working directory. - Buffer-local directories have less priority than window-local ones, and more priority than tab-local ones. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* fix(coverity): RESOURCE_LEAK, USE_AFTER_FREEJustin M. Keyes2026-07-13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | /src/nvim/ex_docmd.c: 5033 in ex_restart() 5027 // The address after --listen may be in use by the current server. 5028 if (i > 0 && strequal(arg, "--listen")) { 5029 const listitem_T *next_li = li->li_next; 5030 if (next_li != NULL) { 5031 const char *addr = tv_get_string(TV_LIST_ITEM_TV(next_li)); 5032 if (strstr(addr, ":") || strstr(addr, "/") || strstr(addr, "\\")) { >>> CID 649201: Resource leaks (RESOURCE_LEAK) >>> Overwriting "listen_arg" in "listen_arg = xstrdup(addr)" leaks the storage that "listen_arg" points to. 5033 listen_arg = TO_SLASH_SAVE(addr); 5034 #ifdef MSWIN 5035 // On Windows, don't pass --listen to new server (named pipe can't be reused immediately). 5036 // Instead pass the address via RPC; new server rebinds after startup. 5037 li = next_li; 5038 continue; *** CID 649200: Memory - illegal accesses (USE_AFTER_FREE) /src/nvim/eval/fs.c: 228 in modify_fname() 222 223 // ":h" - head, remove "/file_name", can be repeated 224 // Don't remove the logical root, see `FileInfo`. 225 while (src[*usedlen] == ':' && src[*usedlen + 1] == 'h') { 226 valid |= VALID_HEAD; 227 *usedlen += 2; >>> CID 649200: Memory - illegal accesses (USE_AFTER_FREE) >>> Using freed pointer "s". 228 while (tail > s && after_pathsep(s, tail)) { 229 MB_PTR_BACK(*fnamep, tail); 230 } 231 *fnamelen = tail <= s ? (size_t)(s - *fnamep) : (size_t)(tail - *fnamep); 232 if (*fnamelen == 0) { 233 // Result is empty. Turn it into "." to make ":cd %:h" work.
* fix(path): normalize separators (slashes) #39155tao2026-07-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Continue separators normalization, and try to keep it at the nvim <-> external boundary, e.g., `fn.xxx`, `api.xxx`, `:xxx` Solution: some key changes - normalize `$HOME-windows` - normalize entry points of changing directory - `nvim_set_current_dir()`, `chdir()` - normalize the named pipe - `--listen` arg, `--server` arg, `:restart` - `serverstart()`, `sockconnect()`, `serverstop()` - make `expand()` respect 'shellslash' again - clean up `did_set_shellslash` - replace `forward_slash` with `TO_SLASH` - remove obsolete `TMP_PATHSEPSTR` - remove `slash_adjust` in `do_autocmd_dirchanged`? - make `fnamemodify()` always return `/` (except when substituting separators via `:s`, `:gs` ?) Note: - these funcs still apply `slash_adjust` on return, as before: `:pwd`, `chdir()`, `exepath()`, `getcwd()` - these funcs alwarys return `/`, unlike before the normalization PRs - `getcompletion()`, `finddir()`, `findfile()` Also - clean up code, comments, formatting and tests - move `TO_SLASH` from `f_chdir` to `changedir_func` - move `TO_SLASH` from `f_bufadd` to `buflist_new` Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* feat(eval): writefile() treats RPC string as "blob"Justin M. Keyes2026-07-11
| | | | related: fb6aeaba2d3a
* feat(path): fnamemodify(':h') preserves logical root #40447tao2026-07-01
| | | | | | | | | | | | | | | | | | | | | | Problem: On Windows, `fnamemodify('//foo/C$', ':h')` incorrectly removes `C$` as a regular file name and returns `//foo`. However, this is a valid UNC path, `foo` is a server name and `C$` is a share name. The correct result should be `//foo/C$`. Solution: Extend `os_fileinfo2` and `FileInfo` with `prefix_off`, `rest_off` to identify path types and logical root boundaries. ':h' can use this info to prevent traversing past the logical root. Examples: /foo => / //foo => // (POSIX) //foo/bar => //foo (POSIX) //server/share/foo => //server/share/ (Windows) C:/foo => C:/ //?/C:/foo => //?/C:/ Co-authored-by: Barrett Ruth <br@barrettruth.com>
* vim-patch:8.2.2117: some functions use any value as a stringJan Edmund Lazo2026-06-21
| | | | | | | | | | | | | | Problem: Some functions use any value as a string. Solution: Check that the value is a non-empty string. ----- Vim9 remains N/A. 5ccc79e880d5913f092e041f1a67530c1d2d6728 ported relevant changes. https://github.com/vim/vim/commit/7bb4e74c38642682cfdd0cb4052adfa5efdd7dd1 Co-authored-by: Bram Moolenaar <Bram@vim.org>
* vim-patch:9.2.0506: home_replace() function can be improved (#39925)zeertzjq2026-05-21
| | | | | | | | | | | | | | | | Problem: home_replace() function can be improved Solution: Refactor home_replace() to return the length of the string (John Marriott). In addition: - in function set_b0_fname() move ulen into the block where it is used. - In function findswapname() rework logic around displaying "swap file already exists" dialogue so that literal message text is set once. closes: vim/vim#20249 https://github.com/vim/vim/commit/a0931a90eeee6692556f330b5ba1fb413f9ea85d Co-authored-by: John Marriott <basilisk@internode.on.net>
* fix(vimscript): normalize multi-slash heads in fnamemodify() #39805Barrett Ruth2026-05-17
| | | | | Problem: `fnamemodify(..., ':h')` mishandles POSIX leading slash runs longer than `//`. Solution: Collapse those slash runs to `/` before computing the head.
* vim-patch:partial:9.2.0341: some functions can be run from the sandbox (#39733)zeertzjq2026-05-11
| | | | | | | | | | | Problem: some functions can be run from the sandbox Solution: Block them, so they are not accessible from a modeline (q1uf3ng) closes: vim/vim#19975 https://github.com/vim/vim/commit/fcc4276db31bc35239186e62921b4ff5a15fb18e Co-authored-by: q1uf3ng <q1uf3ng@protone.me>
* fix(path): exepath() should respect 'shellslash' #39541tao2026-05-04
| | | | | | | | Problem: `gx` relies on `exepath` to get the fullpath of `cmd.exe`, and that path must use `\`; otherwise, luv's spawn will fail. Solution: Revert `slash_adjust` in `exepath`, so that it still respects 'shellslash'
* fix(eval): writestring() handling of null #39328Justin M. Keyes2026-04-26
| | | | | | | | | | | Problem: - write_blob, write_string dereference args which may be NULL. - `writefile(v:_null_blob, …)` fails. Solution: - Fix the annotation. - Handle null blob. Co-authored-by: zeertzjq <zeertzjq@outlook.com>
* docs: misc #39256Justin M. Keyes2026-04-25
|
* fix(path): normalize path slashes on Windows #37729tao2026-04-24
| | | | | | | | | | | | | | | | | | | | Problem: On Windows, path separators may become inconsistent for various reasons, which makes normalization quite painful. Solution: Normalize paths to `/` at the entry boundaries and always use it internally, converting back only in rare cases where `\` is really needed (e.g. cmd.exe/bat scripts?). This is the first commit in a series of incremental steps. Note: * some funcs won't respect shellslash. e.g. `expand/fnamemodify` * some funcs still respect shellslash, but will be updated in a follow PR. e.g. `ex_pwd/f_chdir/f_getcwd` * uv's built-in funcs always return `\`. e.g. `uv.cwd/uv.exepath` Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* feat(eval): treat Lua string as "blob" in writefile() #39098Barrett Ruth2026-04-22
| | | | | | | Problem: vim.fn.writefile() treats Lua strings as Vimscript strings instead of a "binary clean" string. Solution: Treat Lua-originated strings as blob data.
* build: update clang v21, fix warningsdundargoc2026-04-14
| | | | | - `src/nvim/ex_cmds_defs.h`: use "U" instead of "u" per `readability-uppercase-literal-suffix`
* vim-patch:9.2.0031: Inefficient use of ga_concat()zeertzjq2026-02-22
| | | | | | | | | | | | | Problem: Inefficient use of ga_concat() Solution: Use ga_concat_len() when the length is already known to avoid use of strlen() (John Marriott). closes: vim/vim#19422 https://github.com/vim/vim/commit/ed202035b1904c84d92adb76d7e1a95b7540e048 Co-authored-by: John Marriott <basilisk@internode.on.net> Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
* vim-patch:9.1.1648: MS-Windows: some style issues with patch v9.1.1646zeertzjq2026-01-04
| | | | | | | | | Problem: MS-Windows: some style issues with patch v9.1.1646 Solution: Fix typose and code style issues (zeertzjq). closes: vim/vim#18036 https://github.com/vim/vim/commit/14afa278c1bcb2df51b647ffda2821c5294eb7ff
* vim-patch:9.1.1646: MS-Windows: completion cannot handle implicit drive letterszeertzjq2026-01-04
| | | | | | | | | | | | Problem: MS-Windows: completion cannot handle implicit drive letters Solution: Consider paths like \folder and /folder as absolute (Miguel Barro). closes: vim/vim#17829 https://github.com/vim/vim/commit/a2f13bf782f723e116c5d4cc7d79a23e918a24db Co-authored-by: Miguel Barro <miguel.barro@live.com>
* vim-patch:8.1.1979: code for handling file names is spread out (#36176)Jan Edmund Lazo2025-10-15
| | | | | | | | Problem: Code for handling file names is spread out. Solution: Move code to new filepath.c file. Graduate FEAT_MODIFY_FNAME. https://github.com/vim/vim/commit/b005cd80cfda591be95146024d9b97eef383500f Co-authored-by: Bram Moolenaar <Bram@vim.org>
* vim-patch:partial:8.1.1939: code for handling v: variables in generic eval ↵Jan Edmund Lazo2025-10-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | file (#35968) Problem: Code for handling v: variables in generic eval file. Solution: Move v: variables to evalvars.c. (Yegappan Lakshmanan, closes vim/vim#4872) https://github.com/vim/vim/commit/e5cdf153bcb348c68011b308c8988cea42d6ddeb Remove direct reference to "vimvars" for following functions: - assert_error() - get_vim_var_nr() - get_vim_var_list() - get_vim_var_dict() - get_vim_var_str() - set_cmdarg() - set_reg_var() - set_vcount() - set_vexception() - set_vthrowpoint() - set_vim_var_bool() - set_vim_var_dict() - set_vim_var_list() - set_vim_var_nr() - set_vim_var_special() - set_vim_var_string() - set_vim_var_type() Reorder functions based on v8.2.4930 for eval_one_expr_in_str() and eval_all_expr_in_str(). Co-authored-by: Bram Moolenaar <Bram@vim.org>
* refactor: rename ga_concat_strings_sep() to ga_concat_strings() (#35498)zeertzjq2025-08-27
| | | | | | This adds a missing change from Vim patch 7.4.279. N/A patch: vim-patch:9.1.1691: over-allocation in ga_concat_strings()
* refactor(build): remove INCLUDE_GENERATED_DECLARATIONS guardsbfredl2025-08-14
| | | | | | | | | These are not needed after #35129 but making uncrustify still play nice with them was a bit tricky. Unfortunately `uncrustify --update-config-with-doc` breaks strings with backslashes. This issue has been reported upstream, and in the meanwhile auto-update on every single run has been disabled.
* vim-patch:9.1.1605: cannot specify scope for chdir() (#35239)zeertzjq2025-08-08
| | | | | | | | | | Problem: Cannot specify scope for chdir() Solution: Add optional scope argument (kuuote) closes: vim/vim#17888 https://github.com/vim/vim/commit/8a65a49d509d5a9dd5759a4287969896e8941c10 Co-authored-by: kuuote <znmxodq1@gmail.com>
* vim-patch:8.2.4838: checking for absolute path is not trivial (#29990)zeertzjq2024-08-06
| | | | | | | | | | Problem: Checking for absolute path is not trivial. Solution: Add isabsolutepath(). (closes vim/vim#10303) https://github.com/vim/vim/commit/dca1d40cd0f2af0755519e7028378bd3c8fefd31 vim-patch:8a3b805c6c9c Co-authored-by: LemonBoy <thatlemon@gmail.com>
* vim-patch:9.1.0465: missing filecopy() function (#29989)zeertzjq2024-08-06
| | | | | | | | | | | Problem: missing filecopy() function Solution: implement filecopy() Vim script function (Shougo Matsushita) closes: vim/vim#12346 https://github.com/vim/vim/commit/60c8743ab6c90e402e6ed49d27455ef7e5698abe Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
* refactor: extract eval/fs.c from eval/funcs.c (#29985)zeertzjq2024-08-06
In Vim a lot of filesystem functions have been moved to filepath.c. However, some of these functions actually deal with file contents, and Nvim's filesystem-related functions are spread out in a different way. Therefore, it's better to use a different file for these functions.