Archived
1
0
Fork 0

inotify-map: unmap_path, return the amount of remaining paths associated with this wd.

This commit is contained in:
Henrik Hautakoski 2011-02-20 10:50:14 +01:00
parent ab91625700
commit ff91ca59cd
2 changed files with 18 additions and 18 deletions

View file

@ -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() {

View file

@ -63,13 +63,11 @@ 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());