aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2022-01-06 00:10:14 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2022-01-09 23:26:11 +0100
commit7473fbf32c35838511703a3ed79bb2a273812a89 (patch)
treef3724b276a2797df0781b1c0af38353eff81d1be
parent5032e7352e0570644a35f805df1df9d203836677 (diff)
downloadlite-xl-7473fbf32c35838511703a3ed79bb2a273812a89.tar.gz
lite-xl-7473fbf32c35838511703a3ed79bb2a273812a89.zip
Fix undue asserts in dmon_extra
Some asserts are placed in case that can effectively occur so we remove the assertion and we return false. In turn we adapt the logic accordingly so when false is returned to add a watch we do not open that directory.
-rw-r--r--data/core/init.lua8
-rw-r--r--data/plugins/treeview.lua8
-rw-r--r--lib/dmon/dmon_extra.h4
3 files changed, 9 insertions, 11 deletions
diff --git a/data/core/init.lua b/data/core/init.lua
index 67efe11e..05838192 100644
--- a/data/core/init.lua
+++ b/data/core/init.lua
@@ -224,14 +224,14 @@ end
function core.project_subdir_set_show(dir, filename, show)
- dir.shown_subdir[filename] = show
if dir.files_limit and not dir.force_rescan then
local fullpath = dir.name .. PATHSEP .. filename
- local success = (show and system.watch_dir_add or system.watch_dir_rm)(dir.watch_id, fullpath)
- if not success then
- core.log("Internal warning: error calling system.watch_dir_%s", show and "add" or "rm")
+ if not (show and system.watch_dir_add or system.watch_dir_rm)(dir.watch_id, fullpath) then
+ return false
end
end
+ dir.shown_subdir[filename] = show
+ return true
end
diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua
index 9f59bc80..93c43189 100644
--- a/data/plugins/treeview.lua
+++ b/data/plugins/treeview.lua
@@ -230,12 +230,14 @@ function TreeView:on_mouse_pressed(button, x, y, clicks)
if keymap.modkeys["ctrl"] and button == "left" then
create_directory_in(hovered_item)
else
- hovered_item.expanded = not hovered_item.expanded
local hovered_dir = core.project_dir_by_name(hovered_item.dir_name)
if hovered_dir and hovered_dir.files_limit then
- core.update_project_subdir(hovered_dir, hovered_item.filename, hovered_item.expanded)
- core.project_subdir_set_show(hovered_dir, hovered_item.filename, hovered_item.expanded)
+ if not core.project_subdir_set_show(hovered_dir, hovered_item.filename, not hovered_item.expanded) then
+ return
+ end
+ core.update_project_subdir(hovered_dir, hovered_item.filename, not hovered_item.expanded)
end
+ hovered_item.expanded = not hovered_item.expanded
end
else
core.try(function()
diff --git a/lib/dmon/dmon_extra.h b/lib/dmon/dmon_extra.h
index 4b321034..cbacdc93 100644
--- a/lib/dmon/dmon_extra.h
+++ b/lib/dmon/dmon_extra.h
@@ -62,7 +62,6 @@ DMON_API_IMPL bool dmon_watch_add(dmon_watch_id id, const char* watchdir)
dmon__strcpy(fullpath, sizeof(fullpath), watch->rootdir);
dmon__strcat(fullpath, sizeof(fullpath), watchdir);
if (stat(fullpath, &st) != 0 || (st.st_mode & S_IFDIR) == 0) {
- _DMON_LOG_ERRORF("Watch directory '%s' is not valid", watchdir);
if (!skip_lock)
pthread_mutex_unlock(&_dmon.mutex);
return false;
@@ -79,7 +78,6 @@ DMON_API_IMPL bool dmon_watch_add(dmon_watch_id id, const char* watchdir)
// check that the directory is not already added
for (int i = 0, c = stb_sb_count(watch->subdirs); i < c; i++) {
if (strcmp(subdir.rootdir, watch->subdirs[i].rootdir) == 0) {
- _DMON_LOG_ERRORF("Error watching directory '%s', because it is already added.", watchdir);
if (!skip_lock)
pthread_mutex_unlock(&_dmon.mutex);
return false;
@@ -92,7 +90,6 @@ DMON_API_IMPL bool dmon_watch_add(dmon_watch_id id, const char* watchdir)
dmon__strcat(fullpath, sizeof(fullpath), subdir.rootdir);
int wd = inotify_add_watch(watch->fd, fullpath, inotify_mask);
if (wd == -1) {
- _DMON_LOG_ERRORF("Error watching directory '%s'. (inotify_add_watch:err=%d)", watchdir, errno);
if (!skip_lock)
pthread_mutex_unlock(&_dmon.mutex);
return false;
@@ -137,7 +134,6 @@ DMON_API_IMPL bool dmon_watch_rm(dmon_watch_id id, const char* watchdir)
}
}
if (i >= c) {
- _DMON_LOG_ERRORF("Watch directory '%s' is not valid", watchdir);
if (!skip_lock)
pthread_mutex_unlock(&_dmon.mutex);
return false;