summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rhdropbox.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/rhdropbox.c b/rhdropbox.c
index 3c16ba6..5a6c2ee 100644
--- a/rhdropbox.c
+++ b/rhdropbox.c
@@ -123,12 +123,18 @@ int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst
int process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inotify_fd, watch_list_t* watch_lst)
{
int wd = 0;
- if(cmd_id == ADD)
- wd = inotify_add_watch(inotify_fd, path, IN_CLOSE_WRITE | IN_DELETE_SELF | IN_MOVE_SELF | IN_ONLYDIR);
+ int tmp_fd = watch_list_find_fd(watch_lst, path);
+ if(cmd_id == ADD) {
+ if(tmp_fd < 0)
+ wd = inotify_add_watch(inotify_fd, path, IN_CLOSE_WRITE | IN_DELETE_SELF | IN_MOVE_SELF | IN_ONLYDIR);
+ else {
+ log_printf(DEBUG, "cmd_add_remove: path already in watch list");
+ return 0;
+ }
+ }
else if(cmd_id == REMOVE) {
- int fd = watch_list_find_fd(watch_lst, path);
- if(fd >= 0)
- wd = inotify_rm_watch(inotify_fd, fd);
+ if(tmp_fd >= 0)
+ wd = inotify_rm_watch(inotify_fd, tmp_fd);
else {
log_printf(ERROR, "cmd_add_remove path not found in watch list");
send_response(fd, "Error: path not found in watch list");