diff --git a/src/inotify-map.c b/src/inotify-map.c index c51dca9..d0b3389 100644 --- a/src/inotify-map.c +++ b/src/inotify-map.c @@ -113,24 +113,26 @@ static void unmap_path(struct watch *watch) { rbtree_delete(&tree_path_wd, watch); } -static void unmap_wd(struct watch *watch) { +static int unmap_wd(struct watch *watch) { int index; struct list s = { (void**)&watch, 1 }, *list; list = rbtree_search(&tree_wd_paths, &s); - if (!list) - return; + if (list) { - index = list_indexof(list, watch); - if (index >= 0) { - if (list_size(list) == 1) { - list = rbtree_delete(&tree_wd_paths, list); - list_destroy(list); - } else { + index = list_indexof(list, watch); + if (index >= 0) { + if (list_size(list) == 1) { + list = rbtree_delete(&tree_wd_paths, list); + list_destroy(list); + return 0; + } list_remove(list, index); + return list_size(list); } } + return 0; } static void unmap(struct watch *w) { @@ -159,17 +161,17 @@ int inotify_unmap_wd(int wd) { int inotify_unmap_path(const char *path) { + int ret = 0; struct watch *w, s; s.path = path; w = rbtree_search(&tree_path_wd, &s); if (w) { - unmap_wd(w); + ret = unmap_wd(w); unmap_path(w); inotify_watch_destroy(w, unmap); - return 1; } - return 0; + return ret; } void inotify_unmap_all() { diff --git a/test/t_inotify-map.c b/test/t_inotify-map.c index f9f0524..c571410 100644 --- a/test/t_inotify-map.c +++ b/test/t_inotify-map.c @@ -63,15 +63,13 @@ void test_inotify_unmap_wd() { void test_inotify_unmap_path() { - int i; - setup(); - assert(inotify_unmap_path(pathref[0])); - assert(inotify_unmap_path(pathref[1])); - assert(inotify_unmap_path(pathref[2])); + assert(inotify_unmap_path(pathref[0]) == 1); + assert(inotify_unmap_path(pathref[1]) == 0); + assert(inotify_unmap_path(pathref[2]) == 0); assert(inotify_unmap_path(pathref[3]) == 0); - + assert(inotify_map_isempty()); teardown();