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.
This commit is contained in:
parent
5032e7352e
commit
7473fbf32c
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue