Skip to content

Commit

Permalink
feat(scandir): follow symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
SunPodder committed Jul 11, 2023
1 parent bda256f commit 771fa46
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/plenary/scandir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ local gen_search_pat = function(pattern)
end

local process_item = function(opts, name, typ, current_dir, next_dir, bp, data, giti, msp)
if opts.symlink and typ == "link" then
typ = uv.fs_stat(current_dir .. os_sep .. name).type
end

if opts.hidden or name:sub(1, 1) ~= "." then
if typ == "directory" then
local entry = current_dir .. os_sep .. name
Expand Down Expand Up @@ -146,6 +150,7 @@ end
-- opts.search_pattern (regex): regex for which files will be added, string, table of strings, or fn(e) -> bool
-- opts.on_insert(entry): Will be called for each element
-- opts.silent (bool): if true will not echo messages that are not accessible
-- opts.symlink (bool): if true will follow symlinks
-- @return array with files
m.scan_dir = function(path, opts)
opts = opts or {}
Expand Down
1 change: 1 addition & 0 deletions tests/plenary/job.symlink
8 changes: 8 additions & 0 deletions tests/plenary/scandir_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ describe("scandir", function()
eq(false, contains(dirs, "./asdf/asdf/adsf.lua"))
end)

it("with symlinks", function()
local dirs = scan.scan_dir(".", { symlink = true })
eq("table", type(dirs))
eq(true, contains(dirs, "./tests/plenary/job.symlink/validation_spec.lua"))
eq(true, contains(dirs, "./README.md"))
eq(true, contains(dirs, "./lua/plenary/job.lua"))
end)

it("with add directories", function()
local dirs = scan.scan_dir(".", { add_dirs = true })
eq("table", type(dirs))
Expand Down

0 comments on commit 771fa46

Please sign in to comment.