mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 11:15:14 -07:00
Add the . and .. entries to glob()
os_scandir() and os_scandir_next() skip over those, because of the unverlying libuv funcitons behaviour. Fixes #2954
This commit is contained in:
parent
746a4e9f84
commit
ea551044ea
@ -481,6 +481,28 @@ static size_t path_expand(garray_T *gap, const char_u *path, int flags)
|
||||
return do_path_expand(gap, path, 0, flags, false);
|
||||
}
|
||||
|
||||
static const char *scandir_next_with_dots(Directory *dir)
|
||||
{
|
||||
static int count = 0;
|
||||
const char *entry = NULL;
|
||||
if (dir == NULL) {
|
||||
count = 0;
|
||||
} else {
|
||||
count += 1;
|
||||
if (count == 1) {
|
||||
entry = ".";
|
||||
} else if (count == 2) {
|
||||
entry = "..";
|
||||
} else {
|
||||
entry = os_scandir_next(dir);
|
||||
if (entry == NULL) {
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
/// Implementation of path_expand().
|
||||
///
|
||||
/// Chars before `path + wildoff` do not get expanded.
|
||||
@ -597,11 +619,12 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
|
||||
*s = NUL;
|
||||
|
||||
Directory dir;
|
||||
// open the directory for scanning
|
||||
if (os_scandir(&dir, *buf == NUL ? "." : (char *)buf)) {
|
||||
if (os_scandir(&dir, *buf == NUL ? "." : (char *)buf)
|
||||
|| os_isdir(*buf == NUL ? (char_u *)"." : (char_u *)buf)) {
|
||||
// Find all matching entries.
|
||||
char_u *name;
|
||||
while((name = (char_u *) os_scandir_next(&dir))) {
|
||||
scandir_next_with_dots(NULL);
|
||||
while((name = (char_u *) scandir_next_with_dots(&dir)) && name != NULL) {
|
||||
if ((name[0] != '.' || starts_with_dot)
|
||||
&& ((regmatch.regprog != NULL && vim_regexec(®match, name, 0))
|
||||
|| ((flags & EW_NOTWILD)
|
||||
|
21
test/functional/eval/glob_spec.lua
Normal file
21
test/functional/eval/glob_spec.lua
Normal file
@ -0,0 +1,21 @@
|
||||
local helpers = require('test.functional.helpers')
|
||||
local clear, execute, eval, eq = helpers.clear, helpers.execute, helpers.eval, helpers.eq
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
lfs.mkdir('test-glob')
|
||||
execute('cd test-glob')
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
lfs.rmdir('test-glob')
|
||||
end)
|
||||
|
||||
describe('glob()', function()
|
||||
it("glob('.*') returns . and .. ", function()
|
||||
eq({'.', '..'}, eval("glob('.*', 0, 1)"))
|
||||
end)
|
||||
it("glob('*') returns an empty list ", function()
|
||||
eq({}, eval("glob('*', 0, 1)"))
|
||||
end)
|
||||
end)
|
Loading…
Reference in New Issue
Block a user