Enable inotify specific api only on linux

This commit is contained in:
Francesco Abbate 2021-09-29 11:38:03 +02:00
parent 5c4bfd9a77
commit 590c83148e
2 changed files with 18 additions and 10 deletions

View File

@ -155,13 +155,15 @@ function core.project_subdir_set_show(dir, filename, show)
dir.shown_subdir[filename] = show
if dir.files_limit then
local fullpath = dir.name .. PATHSEP .. filename
if show then
local success = system.watch_dir_add(dir.watch_id, fullpath)
print("DEBUG: watch_dir_add", fullpath, "success:", success)
else
print("DEBUG dir", dir.name, "filename", filename, "watch_id:", dir.watch_id)
local success = system.watch_dir_rm(dir.watch_id, fullpath)
print("DEBUG: watch_dir_rm", fullpath, "success:", success)
if PLATFORM == "Linux" then
if show then
local success = system.watch_dir_add(dir.watch_id, fullpath)
print("DEBUG: watch_dir_add", fullpath, "success:", success)
else
print("DEBUG dir", dir.name, "filename", filename, "watch_id:", dir.watch_id)
local success = system.watch_dir_rm(dir.watch_id, fullpath)
print("DEBUG: watch_dir_rm", fullpath, "success:", success)
end
end
end
end
@ -187,8 +189,10 @@ local function scan_project_folder(index)
if entries_count > config.max_project_files then
print("DEBUG setting files limit FLAG for", dir.name)
dir.files_limit = true
-- Watch non-recursively
dir.watch_id = system.watch_dir(dir.name, false)
-- Watch non-recursively on Linux only.
-- The reason is recursively watching with dmon on linux
-- doesn't work on very large directories.
dir.watch_id = system.watch_dir(dir.name, PLATFORM ~= "Linux")
if core.status_view then -- May be not yet initialized.
show_max_files_warning()
end

View File

@ -656,6 +656,7 @@ static int f_watch_dir(lua_State *L) {
return 1;
}
#if __linux__
static int f_watch_dir_add(lua_State *L) {
dmon_watch_id watch_id;
watch_id.id = luaL_checkinteger(L, 1);
@ -672,6 +673,7 @@ static int f_watch_dir_rm(lua_State *L) {
lua_pushboolean(L, dmon_watch_rm(watch_id, subdir));
return 1;
}
#endif
#ifdef _WIN32
#define PATHSEP '\\'
@ -758,9 +760,11 @@ static const luaL_Reg lib[] = {
{ "fuzzy_match", f_fuzzy_match },
{ "set_window_opacity", f_set_window_opacity },
{ "watch_dir", f_watch_dir },
{ "path_compare", f_path_compare },
#if __linux__
{ "watch_dir_add", f_watch_dir_add },
{ "watch_dir_rm", f_watch_dir_rm },
{ "path_compare", f_path_compare },
#endif
{ NULL, NULL }
};