summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2010-01-14 13:48:11 +0000
committerdeva <deva>2010-01-14 13:48:11 +0000
commit65c9b2a123019c4a8618c5d1bb7e4086f3dcd968 (patch)
treecf34990d45c119daef2e2c7160da7628d1cefc78
parentd34d398bc624521d969efab8eb1150c4a6cdeef0 (diff)
Some cleaning up.
-rw-r--r--server/src/inotify.cc88
1 files changed, 19 insertions, 69 deletions
diff --git a/server/src/inotify.cc b/server/src/inotify.cc
index 7834327..c94f809 100644
--- a/server/src/inotify.cc
+++ b/server/src/inotify.cc
@@ -257,8 +257,6 @@ void INotify::addDirectory(std::string name, depth_t depth, uint32_t mask)
if(std::string(dirent->d_name) == "." || std::string(dirent->d_name) == "..")
continue;
- PRACRO_DEBUG(inotify, "Add entry?: %s\n", dirent->d_name);
-
if(isdir(name+"/"+dirent->d_name)) addDirectory(name+"/"+dirent->d_name, depth, mask);
}
@@ -267,7 +265,7 @@ void INotify::addDirectory(std::string name, depth_t depth, uint32_t mask)
int wd = inotify_add_watch(ifd, name.c_str(), mask | IN_ONLYDIR | depth_mask);
if(wd == -1) {
- perror("INotify: Add watch failed!");
+ PRACRO_ERR(inotify, "INotify: Add watch failed on %s\n", name.c_str());
return;
}
@@ -304,7 +302,7 @@ void INotify::readEvents()
ssize_t r;
while( ((r = read(ifd, buf, size)) == -1 && errno == EINVAL) || r == 0 ) {
- fprintf(stderr, "Doubling buffer size: %d\n", size);
+ // fprintf(stderr, "Doubling buffer size: %d\n", size);
size *= 2;
buf = (char*)realloc(buf, size);
}
@@ -314,6 +312,23 @@ void INotify::readEvents()
struct inotify_event *event = (struct inotify_event*)(buf + p);
p += sizeof(struct inotify_event) + event->len;
+ /*
+ switch(event.mask) {
+ case IN_IGNORED:
+ //Watch was removed explicitly (inotify_rm_watch(2)) or automatically
+ // (file was deleted, or file system was unmounted).
+ case IN_ISDIR:
+ //Subject of this event is a directory.
+ case IN_Q_OVERFLOW:
+ //Event queue overflowed (wd is -1 for this event).
+ case IN_UNMOUNT:
+ //File system containing watched object was unmounted.
+ break;
+ default:
+ break;
+ }
+ */
+
// TODO: We need to figure out what the new filename/destination is...
if(TEST(event->mask, IN_MOVE_SELF)) dirmap[event->wd].name = "????????";
@@ -339,37 +354,6 @@ bool INotify::hasEvents()
{
readEvents();
return eventlist.size() > 0;
-
-#if 0
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 0;
-
- fd_set fset;
- int ret;
- FD_ZERO(&fset);
- FD_SET(ifd, &fset);
- ret = select (ifd+1, &fset, NULL, NULL, &tv);
- switch(ret) {
- case -1:
- if(errno == EINTR) {
- // Interrupt
- }
- break;
-
- case 0:
- // Timeout
- break;
-
- default:
- if(FD_ISSET(ifd, &fset)) {
- // Ready read
- return true;
- }
- }
-
- return false;
-#endif
}
INotify::Event INotify::getNextEvent()
@@ -379,40 +363,6 @@ INotify::Event INotify::getNextEvent()
Event e = eventlist.front();
eventlist.pop_front();
return e;
-
-#if 0
- struct inotify_event event;
- ssize_t r = read(ifd, &event, sizeof(struct inotify_event));
- if(r != sizeof(struct inotify_event) && r != -1)
- if(r == sizeof(struct inotify_event)) {
- char *name = NULL;
- if(event.len) {
- name = (char*)malloc(event.len);
- if(read(ifd, name, event.len) != (int)event.len) printf("\n\nFUXK!\n\n");
- }
-
- switch(event.mask) {
- case IN_IGNORED:
- //Watch was removed explicitly (inotify_rm_watch(2)) or automatically
- // (file was deleted, or file system was unmounted).
- case IN_ISDIR:
- //Subject of this event is a directory.
- case IN_Q_OVERFLOW:
- //Event queue overflowed (wd is -1 for this event).
- case IN_UNMOUNT:
- //File system containing watched object was unmounted.
- break;
- default:
- break;
- }
-
- if(TEST(event.mask, IN_IGNORED)) dirmap.erase(event.wd);
- Event e((name!=NULL)?name:"", event.mask);
- if(name) free(name);
- return e;
- }
- return Event("", 0);
-#endif
}
#ifdef TEST_INOTIFY