Update dmon from septag/dmon with fix for linux
Update from https://github.com/septag/dmon, commit: 48234fc2 to include a fix for linux.
This commit is contained in:
parent
1ba385eb5e
commit
09d2c0a325
42
src/dmon.h
42
src/dmon.h
|
@ -763,19 +763,6 @@ _DMON_PRIVATE void dmon__watch_recursive(const char* dirname, int fd, uint32_t m
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
_DMON_PRIVATE const char* dmon__find_subdir(const dmon__watch_state* watch, int wd)
|
|
||||||
{
|
|
||||||
const int* wds = watch->wds;
|
|
||||||
for (int i = 0, c = stb_sb_count(wds); i < c; i++) {
|
|
||||||
if (wd == wds[i]) {
|
|
||||||
return watch->subdirs[i].rootdir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DMON_ASSERT(0);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
_DMON_PRIVATE void dmon__inotify_process_events(void)
|
_DMON_PRIVATE void dmon__inotify_process_events(void)
|
||||||
{
|
{
|
||||||
for (int i = 0, c = stb_sb_count(_dmon.events); i < c; i++) {
|
for (int i = 0, c = stb_sb_count(_dmon.events); i < c; i++) {
|
||||||
|
@ -811,10 +798,9 @@ _DMON_PRIVATE void dmon__inotify_process_events(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (check_ev->mask == IN_MODIFY &&
|
} else if (check_ev->mask == IN_MODIFY && strcmp(ev->filepath, check_ev->filepath) == 0) {
|
||||||
strcmp(ev->filepath, check_ev->filepath) == 0) {
|
|
||||||
// Another case is that file is copied. CREATE and MODIFY happens sequentially
|
// Another case is that file is copied. CREATE and MODIFY happens sequentially
|
||||||
// so we ignore modify event
|
// so we ignore MODIFY event
|
||||||
check_ev->skip = true;
|
check_ev->skip = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -867,12 +853,10 @@ _DMON_PRIVATE void dmon__inotify_process_events(void)
|
||||||
|
|
||||||
switch (ev->mask) {
|
switch (ev->mask) {
|
||||||
case IN_CREATE:
|
case IN_CREATE:
|
||||||
watch->watch_cb(ev->watch_id, DMON_ACTION_CREATE, watch->rootdir, ev->filepath, NULL,
|
watch->watch_cb(ev->watch_id, DMON_ACTION_CREATE, watch->rootdir, ev->filepath, NULL, watch->user_data);
|
||||||
watch->user_data);
|
|
||||||
break;
|
break;
|
||||||
case IN_MODIFY:
|
case IN_MODIFY:
|
||||||
watch->watch_cb(ev->watch_id, DMON_ACTION_MODIFY, watch->rootdir, ev->filepath, NULL,
|
watch->watch_cb(ev->watch_id, DMON_ACTION_MODIFY, watch->rootdir, ev->filepath, NULL, watch->user_data);
|
||||||
watch->user_data);
|
|
||||||
break;
|
break;
|
||||||
case IN_MOVED_FROM: {
|
case IN_MOVED_FROM: {
|
||||||
for (int j = i + 1; j < c; j++) {
|
for (int j = i + 1; j < c; j++) {
|
||||||
|
@ -885,8 +869,7 @@ _DMON_PRIVATE void dmon__inotify_process_events(void)
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case IN_DELETE:
|
case IN_DELETE:
|
||||||
watch->watch_cb(ev->watch_id, DMON_ACTION_DELETE, watch->rootdir, ev->filepath, NULL,
|
watch->watch_cb(ev->watch_id, DMON_ACTION_DELETE, watch->rootdir, ev->filepath, NULL, watch->user_data);
|
||||||
watch->user_data);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -921,15 +904,20 @@ static void* dmon__thread(void* arg)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < _dmon.num_watches; i++) {
|
// Create read FD set
|
||||||
dmon__watch_state* watch = &_dmon.watches[i];
|
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
|
for (int i = 0; i < _dmon.num_watches; i++) {
|
||||||
|
dmon__watch_state* watch = &_dmon.watches[i];
|
||||||
FD_SET(watch->fd, &rfds);
|
FD_SET(watch->fd, &rfds);
|
||||||
|
}
|
||||||
|
|
||||||
timeout.tv_sec = 0;
|
timeout.tv_sec = 0;
|
||||||
timeout.tv_usec = 100000;
|
timeout.tv_usec = 100000;
|
||||||
|
|
||||||
if (select(FD_SETSIZE, &rfds, NULL, NULL, &timeout)) {
|
if (select(FD_SETSIZE, &rfds, NULL, NULL, &timeout)) {
|
||||||
|
for (int i = 0; i < _dmon.num_watches; i++) {
|
||||||
|
dmon__watch_state* watch = &_dmon.watches[i];
|
||||||
|
if (FD_ISSET(watch->fd, &rfds)) {
|
||||||
ssize_t offset = 0;
|
ssize_t offset = 0;
|
||||||
ssize_t len = read(watch->fd, buff, _DMON_TEMP_BUFFSIZE);
|
ssize_t len = read(watch->fd, buff, _DMON_TEMP_BUFFSIZE);
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
|
@ -940,8 +928,7 @@ static void* dmon__thread(void* arg)
|
||||||
struct inotify_event* iev = (struct inotify_event*)&buff[offset];
|
struct inotify_event* iev = (struct inotify_event*)&buff[offset];
|
||||||
|
|
||||||
char filepath[DMON_MAX_PATH];
|
char filepath[DMON_MAX_PATH];
|
||||||
dmon__strcpy(filepath, sizeof(filepath), dmon__find_subdir(watch, iev->wd));
|
dmon__strcpy(filepath, sizeof(filepath), iev->name);
|
||||||
dmon__strcat(filepath, sizeof(filepath), iev->name);
|
|
||||||
|
|
||||||
// TODO: ignore directories if flag is set
|
// TODO: ignore directories if flag is set
|
||||||
|
|
||||||
|
@ -956,6 +943,7 @@ static void* dmon__thread(void* arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct timeval tm;
|
struct timeval tm;
|
||||||
gettimeofday(&tm, 0);
|
gettimeofday(&tm, 0);
|
||||||
|
|
Loading…
Reference in New Issue