@@ -4,6 +4,8 @@ local utils = require("nvim-tree.utils")
4
4
5
5
local Class = require (" nvim-tree.classic" )
6
6
7
+ local MESSAGE_EMFILE = " fs.inotify.max_user_watches exceeded, see https://github.com/nvim-tree/nvim-tree.lua/wiki/Troubleshooting"
8
+
7
9
local FS_EVENT_FLAGS = {
8
10
-- inotify or equivalent will be used; fallback to stat has not yet been implemented
9
11
stat = false ,
@@ -75,6 +77,18 @@ function Event:start()
75
77
local event_cb = vim .schedule_wrap (function (err , filename )
76
78
if err then
77
79
log .line (" watcher" , " event_cb '%s' '%s' FAIL : %s" , self .path , filename , err )
80
+
81
+ -- do nothing if watchers have already been disabled
82
+ if not M .config .filesystem_watchers .enable then
83
+ return
84
+ end
85
+
86
+ -- EMFILE is catastrophic
87
+ if name == " EMFILE" then
88
+ M .disable_watchers (MESSAGE_EMFILE )
89
+ return
90
+ end
91
+
78
92
local message = string.format (" File system watcher failed (%s) for path %s, halting watcher." , err , self .path )
79
93
if err == " EPERM" and (utils .is_windows or utils .is_wsl ) then
80
94
-- on directory removal windows will cascade the filesystem events out of order
@@ -94,7 +108,7 @@ function Event:start()
94
108
rc , _ , name = self .fs_event :start (self .path , FS_EVENT_FLAGS , event_cb )
95
109
if rc ~= 0 then
96
110
if name == " EMFILE" then
97
- M .disable_watchers (" fs.inotify.max_user_watches exceeded, see https://github.com/nvim-tree/nvim-tree.lua/wiki/Troubleshooting " )
111
+ M .disable_watchers (MESSAGE_EMFILE )
98
112
else
99
113
notify .warn (string.format (" Could not start the fs_event watcher for path %s : %s" , self .path , name ))
100
114
end
0 commit comments