Skip to content

Commit 796628a

Browse files
authored
Update symlinks if they have been modified. (#328)
1 parent c235df7 commit 796628a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lua/nvim-tree/populate.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,23 @@ local function link_new(cwd, name)
6262
--- I dont know if this is needed, because in my understanding, there isnt hard links in windows, but just to be sure i changed it.
6363
local absolute_path = utils.path_join({ cwd, name })
6464
local link_to = luv.fs_realpath(absolute_path)
65+
local stat = luv.fs_stat(absolute_path)
6566
local open, entries
6667
if (link_to ~= nil) and luv.fs_stat(link_to).type == 'directory' then
6768
open = false
6869
entries = {}
6970
end
71+
72+
local last_modified = 0
73+
if stat ~= nil then
74+
last_modified = stat.mtime.sec
75+
end
76+
7077
return {
7178
name = name,
7279
absolute_path = absolute_path,
7380
link_to = link_to,
81+
last_modified = last_modified,
7482
open = open,
7583
group_next = nil, -- If node is grouped, this points to the next child dir/link node
7684
entries = entries,
@@ -198,6 +206,16 @@ function M.refresh_entries(entries, cwd, parent_node)
198206

199207
local idx = 1
200208
for _, name in ipairs(cached_entries) do
209+
local node = named_entries[name]
210+
if node and node.link_to then
211+
-- If the link has been modified: remove it in case the link target has changed.
212+
local stat = luv.fs_stat(node.absolute_path)
213+
if stat and node.last_modified ~= stat.mtime.sec then
214+
new_entries[name] = nil
215+
named_entries[name] = nil
216+
end
217+
end
218+
201219
if not new_entries[name] then
202220
table.remove(entries, idx)
203221
else

0 commit comments

Comments
 (0)