fix some path handling issues
This commit is contained in:
@@ -78,10 +78,27 @@ static hiFileEvent file_event_create(const struct inotify_event *inevent,
|
||||
}
|
||||
|
||||
if (inevent->len) {
|
||||
#define BUFSIZE 1024
|
||||
char filename[BUFSIZE];
|
||||
size_t parent_name_size = strlen(fw->path);
|
||||
size_t event_path_size = strlen(inevent->name);
|
||||
size_t fullpath_size = parent_name_size + event_path_size;
|
||||
if (fullpath_size > BUFSIZE - 1) {
|
||||
sc_log_error("Pathname length over %u, please compile with smaller "
|
||||
"paths. Event discarded for %s\n.", BUFSIZE - 1,
|
||||
inevent->name);
|
||||
return NULL_EVENT;
|
||||
}
|
||||
#undef BUFSIZE
|
||||
|
||||
strncpy(filename, fw->path, parent_name_size);
|
||||
strncpy(filename + parent_name_size, inevent->name, event_path_size);
|
||||
filename[fullpath_size] = '\0';
|
||||
|
||||
// find if file is associated with any path
|
||||
for (size_t i = 0; i < sc_array_size(&fw->files); ++i) {
|
||||
const char *watched_file = sc_array_at(&fw->files, i);
|
||||
if (strcmp(watched_file, inevent->name)) {
|
||||
if (strcmp(watched_file, filename) == 0) {
|
||||
|
||||
// check if event mask matches the watcher mask
|
||||
hiWatchParams *params =
|
||||
@@ -117,7 +134,6 @@ static hiFileEvent file_event_create(const struct inotify_event *inevent,
|
||||
return NULL_EVENT;
|
||||
}
|
||||
// Event on the folder itself
|
||||
|
||||
return NULL_EVENT;
|
||||
}
|
||||
|
||||
@@ -287,8 +303,9 @@ int file_watcher_watch(void *arg) {
|
||||
sc_array_add(&ctx->events, e);
|
||||
|
||||
if (event->len) {
|
||||
sc_log_debug("Event created: queue-size: %u, %s: %s\n", sc_array_size(&ctx->events),
|
||||
e.pathname, hi_file_watch_type_to_str(e.type));
|
||||
sc_log_debug("Event created: queue-size: %u, %s %s\n",
|
||||
sc_array_size(&ctx->events), e.pathname,
|
||||
hi_file_watch_type_to_str(e.type));
|
||||
}
|
||||
}
|
||||
continue; // read again without waiting
|
||||
|
||||
Reference in New Issue
Block a user