From cb55e3336f5137f4459c2190159b3649b552ab86 Mon Sep 17 00:00:00 2001 From: Sunlight <73415680+SunPodder@users.noreply.github.com> Date: Mon, 10 Jul 2023 16:41:03 +0600 Subject: [PATCH] feat(scandir): follow symlinks --- lua/plenary/scandir.lua | 5 +++++ tests/plenary/job.symlink | 1 + tests/plenary/scandir_spec.lua | 8 ++++++++ 3 files changed, 14 insertions(+) create mode 120000 tests/plenary/job.symlink diff --git a/lua/plenary/scandir.lua b/lua/plenary/scandir.lua index fd35fd9f..2768ace8 100644 --- a/lua/plenary/scandir.lua +++ b/lua/plenary/scandir.lua @@ -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 @@ -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 {} diff --git a/tests/plenary/job.symlink b/tests/plenary/job.symlink new file mode 120000 index 00000000..cb62da54 --- /dev/null +++ b/tests/plenary/job.symlink @@ -0,0 +1 @@ +job \ No newline at end of file diff --git a/tests/plenary/scandir_spec.lua b/tests/plenary/scandir_spec.lua index 9c158082..c4865e6e 100644 --- a/tests/plenary/scandir_spec.lua +++ b/tests/plenary/scandir_spec.lua @@ -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))