From 796628a7651f9399637ad8376bab920fb10493cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20T=2E=20Str=C3=B8m?= Date: Tue, 20 Apr 2021 23:48:23 +0200 Subject: [PATCH] Update symlinks if they have been modified. (#328) --- lua/nvim-tree/populate.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lua/nvim-tree/populate.lua b/lua/nvim-tree/populate.lua index 07089327..cc9ee881 100644 --- a/lua/nvim-tree/populate.lua +++ b/lua/nvim-tree/populate.lua @@ -62,15 +62,23 @@ local function link_new(cwd, name) --- 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. local absolute_path = utils.path_join({ cwd, name }) local link_to = luv.fs_realpath(absolute_path) + local stat = luv.fs_stat(absolute_path) local open, entries if (link_to ~= nil) and luv.fs_stat(link_to).type == 'directory' then open = false entries = {} end + + local last_modified = 0 + if stat ~= nil then + last_modified = stat.mtime.sec + end + return { name = name, absolute_path = absolute_path, link_to = link_to, + last_modified = last_modified, open = open, group_next = nil, -- If node is grouped, this points to the next child dir/link node entries = entries, @@ -198,6 +206,16 @@ function M.refresh_entries(entries, cwd, parent_node) local idx = 1 for _, name in ipairs(cached_entries) do + local node = named_entries[name] + if node and node.link_to then + -- If the link has been modified: remove it in case the link target has changed. + local stat = luv.fs_stat(node.absolute_path) + if stat and node.last_modified ~= stat.mtime.sec then + new_entries[name] = nil + named_entries[name] = nil + end + end + if not new_entries[name] then table.remove(entries, idx) else