7
7
-- Adapted from: https://github.com/rktjmp/fwatch.nvim
8
8
--
9
9
10
- local Path = require (" plenary.path" )
11
- local Scan = require (" plenary.scandir" )
10
+ local Path = require (" pathlib" )
12
11
13
12
local uv = vim .loop
14
13
local fs_stat = uv .fs_stat
@@ -45,15 +44,18 @@ local function do_watch(path, on_event, on_error)
45
44
on_event (filename , unwatch_cb )
46
45
end
47
46
end
48
- uv .fs_event_start (handle , path , {}, event_cb )
47
+ uv .fs_event_start (handle , tostring ( path ) , {}, event_cb )
49
48
table.insert (handles , handle )
50
49
end
51
50
52
51
--- Gets all directories in the library_dir
53
52
--- @return table #A list of all directories in library_dir
54
53
local function get_library_dirs ()
55
- local library_dir = Path :new (db .config :get_value ({ id = 1 }, " dir" )):expand ()
56
- local library_dirs = Scan .scan_dir (library_dir , { depth = 1 , only_dirs = true })
54
+ local library_dir = Path (db .config :get_value ({ id = 1 }, " dir" ))
55
+ local library_dirs = {}
56
+ for path in library_dir :fs_iterdir () do
57
+ table.insert (library_dirs , path )
58
+ end
57
59
return library_dirs
58
60
end
59
61
@@ -75,7 +77,7 @@ local function init_fs_watcher(dir_to_watch, is_library_root)
75
77
local do_update = true
76
78
if is_library_root then
77
79
log .debug (" Filesystem event in the library root directory" )
78
- entry_dir = Path : new (dir_to_watch , filename )
80
+ entry_dir = Path (dir_to_watch , filename )
79
81
info_path = entry_dir :joinpath (info_name )
80
82
if entry_dir :exists () and entry_dir :is_dir () then
81
83
log .debug (string.format (" Filesystem event: path '%s' added" , entry_dir :absolute ()))
@@ -93,7 +95,7 @@ local function init_fs_watcher(dir_to_watch, is_library_root)
93
95
end
94
96
else
95
97
log .debug (" Filesystem event in entry directory" )
96
- entry_dir = Path : new (dir_to_watch )
98
+ entry_dir = Path (dir_to_watch )
97
99
info_path = entry_dir :joinpath (info_name )
98
100
if info_path :exists () then
99
101
-- info file exists, update with new info
151
153
--- Starts file system watchers for root dir and all entry dirs
152
154
local function start_fs_watchers ()
153
155
log .debug (" Set db state to indicate fswatcher is active" )
154
- local library_dir = Path : new (db .config :get_value ({ id = 1 }, " dir" )): expand ( )
156
+ local library_dir = Path (db .config :get_value ({ id = 1 }, " dir" ))
155
157
db .state :set_fw_running (uv .os_getpid ())
156
158
157
159
log .debug (" Setting up fswatcher for library root directory" )
0 commit comments