Commits

Robert Lowry committed 09e81b8

made add_watch() function, used it in add_dir_inotify

Comments (0)

Files changed (1)

 
 typedef struct watch_t watch_t;
 struct watch_t {
+	int wd;
 	int pid;
+	int isdir;
 	char *path;
 	watch_t *next;
-	int wd;
 };
 
 watch_t *watch = NULL;
 	return w;
 }
 
+
+
 void spawn_win(watch_t *w)
 {
 	char out[PATH_MAX], in[PATH_MAX], path[PATH_MAX], channel[32];
 	}
 }
 
+watch_t *add_watch(int wd, const char *path, int isdir)
+{
+	char out[PATH_MAX];
+	struct stat st;
+	watch_t *w;
+
+	/* TODO: clean this up (once everything else works) */
+	if (!watch) {
+		watch = new_watch();
+		watch->wd = wd;
+	}
+	for(w = watch; w; w = w->next) {
+		if (w->wd == wd) {
+			w->isdir = isdir;
+			if(!w->path) {
+				w->path = strdup(path);
+				if(w->isdir) {
+					snprintf(out,sizeof(out),"%s/out",path);
+					if(!init && stat(out, &st) == 0)
+						spawn_win(w);
+				}
+			}
+			break;
+		}
+		if (w->next == NULL) {
+			w->next = new_watch();
+			w->next->wd = wd;
+		}
+	}
+	
+	return w;
+}
+
 #ifdef HAVE_INOTIFY
 int add_dir_inotify(const char *fpath, const struct stat *sb, int typeflag)
 {
-	char out[PATH_MAX];
-	struct stat st;
 	watch_t *w;
 	int wd;
 
 		return 0;
 	}
 
-	/* TODO: oops, this can be simplified greatly */
-	if (!watch) {
-		watch = new_watch();
-		watch->wd = wd;
-	}
-	for(w = watch; w; w = w->next) {
-		if (w->wd == wd) {
-			if(!w->path) {
-				w->path = strdup(fpath);
-				snprintf(out,sizeof(out),"%s/out",fpath);
-				if(!init && stat(out, &st) == 0)
-					spawn_win(w);
-			}
-			break;
-		}
-		if (w->next == NULL) {
-			w->next = new_watch();
-			w->next->wd = wd;
-		}
-	}
+	w = add_watch(wd,fpath,1);
+
 	return 0;
 }
 
 	if(kevent(kq, &kadd, 1, NULL, 0, NULL) == -1)
 		err(1,"kevent set EVFILT_VNODE");
 
+	/* TODO: replace with add_watch()*/
 	if (!watch)
 		watch = new_watch();
 	for(w = watch; w; w = w->next)