@@ -85,30 +85,23 @@ function M.reload(node, git_status)
85
85
node .group_next = nil
86
86
end
87
87
88
- local child_names = {}
88
+ local remain_childs = {}
89
89
90
90
local node_ignored = explorer_node .is_git_ignored (node )
91
+ --- @type table<string , Node>
91
92
local nodes_by_path = utils .key_by (node .nodes , " absolute_path" )
92
93
while true do
93
94
local name , t = vim .loop .fs_scandir_next (handle , cwd )
94
95
if not name then
95
96
break
96
97
end
97
98
98
- local stat
99
- local function fs_stat_cached (path )
100
- if stat ~= nil then
101
- return stat
102
- end
103
-
104
- stat = vim .loop .fs_stat (path )
105
- return stat
106
- end
107
-
108
99
local abs = utils .path_join { cwd , name }
109
- t = t or (fs_stat_cached (abs ) or {}).type
110
- if not filters .should_filter (abs , filter_status ) then
111
- child_names [abs ] = true
100
+ --- @type uv.fs_stat.result | nil
101
+ local stat = vim .loop .fs_stat (abs )
102
+
103
+ if not filters .should_filter (abs , stat , filter_status ) then
104
+ remain_childs [abs ] = true
112
105
113
106
-- Recreate node if type changes.
114
107
if nodes_by_path [abs ] then
@@ -122,26 +115,26 @@ function M.reload(node, git_status)
122
115
end
123
116
124
117
if not nodes_by_path [abs ] then
118
+ local new_child = nil
125
119
if t == " directory" and vim .loop .fs_access (abs , " R" ) and Watcher .is_fs_event_capable (abs ) then
126
- local folder = builders .folder (node , abs , name )
127
- nodes_by_path [abs ] = folder
128
- table.insert (node .nodes , folder )
120
+ new_child = builders .folder (node , abs , name , stat )
129
121
elseif t == " file" then
130
- local file = builders .file (node , abs , name )
131
- nodes_by_path [abs ] = file
132
- table.insert (node .nodes , file )
122
+ new_child = builders .file (node , abs , name , stat )
133
123
elseif t == " link" then
134
- local link = builders .link (node , abs , name )
124
+ local link = builders .link (node , abs , name , stat )
135
125
if link .link_to ~= nil then
136
- nodes_by_path [abs ] = link
137
- table.insert (node .nodes , link )
126
+ new_child = link
138
127
end
139
128
end
129
+ if new_child then
130
+ table.insert (node .nodes , new_child )
131
+ nodes_by_path [abs ] = new_child
132
+ end
140
133
else
141
134
local n = nodes_by_path [abs ]
142
135
if n then
143
- n .executable = builders .is_executable (abs )
144
- n .fs_stat = fs_stat_cached ( abs )
136
+ n .executable = builders .is_executable (abs ) or false
137
+ n .fs_stat = stat
145
138
end
146
139
end
147
140
end
@@ -150,8 +143,8 @@ function M.reload(node, git_status)
150
143
node .nodes = vim .tbl_map (
151
144
update_status (nodes_by_path , node_ignored , git_status ),
152
145
vim .tbl_filter (function (n )
153
- if child_names [n .absolute_path ] then
154
- return child_names [n .absolute_path ]
146
+ if remain_childs [n .absolute_path ] then
147
+ return remain_childs [n .absolute_path ]
155
148
else
156
149
explorer_node .node_destroy (n )
157
150
return false
0 commit comments