Archived
1
0
Fork 0

inotify.c: trigger correct types for symlinks.

This commit is contained in:
Henrik Hautakoski 2011-03-03 08:50:14 +01:00
parent 0d53ab7bbc
commit 36358cf9d0
2 changed files with 37 additions and 17 deletions

View file

@ -32,7 +32,7 @@ obj-log = src/log.o $(obj-strbuf) $(obj-xalloc)
obj-inotify-backend = src/inotify-backend.o $(obj-log) obj-inotify-backend = src/inotify-backend.o $(obj-log)
obj-inotify-watch = src/inotify-watch.o $(obj-tree) obj-inotify-watch = src/inotify-watch.o $(obj-tree)
obj-inotify-map = src/inotify-map.o $(obj-inotify-watch) $(obj-path) $(obj-rbtree) $(obj-list) obj-inotify-map = src/inotify-map.o $(obj-inotify-watch) $(obj-path) $(obj-rbtree) $(obj-list)
obj-inotify = src/inotify.o src/queue.o $(obj-inotify-backend) $(obj-inotify-map) obj-inotify = src/inotify.o src/queue.o $(obj-path) $(obj-inotify-backend) $(obj-inotify-map)
obj-notify-inotify = src/notify-inotify.o $(obj-inotify) $(obj-xalloc) $(obj-fscrawl) obj-notify-inotify = src/notify-inotify.o $(obj-inotify) $(obj-xalloc) $(obj-fscrawl)
obj-notify = src/event.o $(obj-notify-inotify) obj-notify = src/event.o $(obj-notify-inotify)

View file

@ -3,6 +3,7 @@
#include "log.h" #include "log.h"
#include "path.h" #include "path.h"
#include "queue.h" #include "queue.h"
#include "path.h"
#include "inotify-backend.h" #include "inotify-backend.h"
#include "inotify-map.h" #include "inotify-map.h"
#include "inotify.h" #include "inotify.h"
@ -43,7 +44,7 @@ int inotify_ignore(const char *path) {
int wd = inotify_map_get_wd(path); int wd = inotify_map_get_wd(path);
if (wd < 0) if (wd <= 0)
return -1; return -1;
/* unmap and remove watch */ /* unmap and remove watch */
@ -60,7 +61,6 @@ static void proc_event(struct inotify_event *iev) {
int i; int i;
struct list *watch_list; struct list *watch_list;
int isdir;
logmsg(LOG_DEBUG, "RAW EVENT: %i, %x, %s", iev->wd, iev->mask, iev->name); logmsg(LOG_DEBUG, "RAW EVENT: %i, %x, %s", iev->wd, iev->mask, iev->name);
@ -77,10 +77,6 @@ static void proc_event(struct inotify_event *iev) {
return; return;
} }
/* set dir and drop that bit off (so its not in the way) */
isdir = (iev->mask & IN_ISDIR) != 0;
iev->mask &= ~IN_ISDIR;
for(i=0; i < watch_list->nr; i++) { for(i=0; i < watch_list->nr; i++) {
struct watch *watch = watch_list->items[i]; struct watch *watch = watch_list->items[i];
@ -88,19 +84,43 @@ static void proc_event(struct inotify_event *iev) {
notify_event_set_path(event, watch->path); notify_event_set_path(event, watch->path);
notify_event_set_filename(event, iev->name); notify_event_set_filename(event, iev->name);
event->dir = isdir;
switch(iev->mask) { /*
case IN_CREATE : * Because of limitation on the information we get from inotify
case IN_MOVED_TO : * We must do something else to find out what type a "file/link" should be.
*
* if CREATE or MOVED_TO:
* The file is present on the filesystem, so we
* only need to perform a simple system call.
*
* if DELETE or MOVED_FROM:
* The file is no longer present on the filesystem, but
* we will treat the symlink as a directory if we are
* watching the path. since we only watch directories.
* otherwise it may be a symlink we simple do not care about
* or some other file.
*/
if (iev->mask & IN_CREATE || iev->mask & IN_MOVED_TO) {
event->dir = (iev->mask & IN_ISDIR) ? 1 :
is_dir(mkpath("%s/%s", event->path, event->filename));
event->type = NOTIFY_CREATE; event->type = NOTIFY_CREATE;
break; } else if (iev->mask & IN_DELETE || iev->mask & IN_MOVED_FROM) {
case IN_DELETE :
case IN_MOVED_FROM : if (iev->mask & IN_ISDIR) {
event->dir = 1;
} else {
const char *path = mkpath("%s%s/", event->path, event->filename);
if (inotify_map_get_wd(path) > 0) {
inotify_unmap_path(path);
event->dir = 1;
} else {
event->dir = 0;
}
}
event->type = NOTIFY_DELETE; event->type = NOTIFY_DELETE;
inotify_ignore(mkpath("%s%s/", event->path, event->filename)); } else {
break;
default:
event->type = NOTIFY_UNKNOWN; event->type = NOTIFY_UNKNOWN;
} }