Skip to content

Commit cb55e33

Browse files
committed
feat(scandir): follow symlinks
1 parent 4f71c0c commit cb55e33

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

lua/plenary/scandir.lua

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ local gen_search_pat = function(pattern)
100100
end
101101

102102
local process_item = function(opts, name, typ, current_dir, next_dir, bp, data, giti, msp)
103+
if opts.symlink and typ == "link" then
104+
typ = uv.fs_stat(current_dir .. os_sep .. name).type
105+
end
106+
103107
if opts.hidden or name:sub(1, 1) ~= "." then
104108
if typ == "directory" then
105109
local entry = current_dir .. os_sep .. name
@@ -146,6 +150,7 @@ end
146150
-- opts.search_pattern (regex): regex for which files will be added, string, table of strings, or fn(e) -> bool
147151
-- opts.on_insert(entry): Will be called for each element
148152
-- opts.silent (bool): if true will not echo messages that are not accessible
153+
-- opts.symlink (bool): if true will follow symlinks
149154
-- @return array with files
150155
m.scan_dir = function(path, opts)
151156
opts = opts or {}

tests/plenary/job.symlink

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
job

tests/plenary/scandir_spec.lua

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ describe("scandir", function()
6565
eq(false, contains(dirs, "./asdf/asdf/adsf.lua"))
6666
end)
6767

68+
it("with symlinks", function()
69+
local dirs = scan.scan_dir(".", { symlink = true })
70+
eq("table", type(dirs))
71+
eq(true, contains(dirs, "./tests/plenary/job.symlink/validation_spec.lua"))
72+
eq(true, contains(dirs, "./README.md"))
73+
eq(true, contains(dirs, "./lua/plenary/job.lua"))
74+
end)
75+
6876
it("with add directories", function()
6977
local dirs = scan.scan_dir(".", { add_dirs = true })
7078
eq("table", type(dirs))

0 commit comments

Comments
 (0)