inotify-map: unmap_path, return the amount of remaining paths associated with this wd.
This commit is contained in:
parent
ab91625700
commit
ff91ca59cd
2 changed files with 18 additions and 18 deletions
|
|
@ -113,24 +113,26 @@ static void unmap_path(struct watch *watch) {
|
||||||
rbtree_delete(&tree_path_wd, watch);
|
rbtree_delete(&tree_path_wd, watch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unmap_wd(struct watch *watch) {
|
static int unmap_wd(struct watch *watch) {
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
struct list s = { (void**)&watch, 1 }, *list;
|
struct list s = { (void**)&watch, 1 }, *list;
|
||||||
|
|
||||||
list = rbtree_search(&tree_wd_paths, &s);
|
list = rbtree_search(&tree_wd_paths, &s);
|
||||||
if (!list)
|
if (list) {
|
||||||
return;
|
|
||||||
|
|
||||||
index = list_indexof(list, watch);
|
index = list_indexof(list, watch);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
if (list_size(list) == 1) {
|
if (list_size(list) == 1) {
|
||||||
list = rbtree_delete(&tree_wd_paths, list);
|
list = rbtree_delete(&tree_wd_paths, list);
|
||||||
list_destroy(list);
|
list_destroy(list);
|
||||||
} else {
|
return 0;
|
||||||
|
}
|
||||||
list_remove(list, index);
|
list_remove(list, index);
|
||||||
|
return list_size(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unmap(struct watch *w) {
|
static void unmap(struct watch *w) {
|
||||||
|
|
@ -159,17 +161,17 @@ int inotify_unmap_wd(int wd) {
|
||||||
|
|
||||||
int inotify_unmap_path(const char *path) {
|
int inotify_unmap_path(const char *path) {
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
struct watch *w, s;
|
struct watch *w, s;
|
||||||
|
|
||||||
s.path = path;
|
s.path = path;
|
||||||
w = rbtree_search(&tree_path_wd, &s);
|
w = rbtree_search(&tree_path_wd, &s);
|
||||||
if (w) {
|
if (w) {
|
||||||
unmap_wd(w);
|
ret = unmap_wd(w);
|
||||||
unmap_path(w);
|
unmap_path(w);
|
||||||
inotify_watch_destroy(w, unmap);
|
inotify_watch_destroy(w, unmap);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void inotify_unmap_all() {
|
void inotify_unmap_all() {
|
||||||
|
|
|
||||||
|
|
@ -63,13 +63,11 @@ void test_inotify_unmap_wd() {
|
||||||
|
|
||||||
void test_inotify_unmap_path() {
|
void test_inotify_unmap_path() {
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
assert(inotify_unmap_path(pathref[0]));
|
assert(inotify_unmap_path(pathref[0]) == 1);
|
||||||
assert(inotify_unmap_path(pathref[1]));
|
assert(inotify_unmap_path(pathref[1]) == 0);
|
||||||
assert(inotify_unmap_path(pathref[2]));
|
assert(inotify_unmap_path(pathref[2]) == 0);
|
||||||
assert(inotify_unmap_path(pathref[3]) == 0);
|
assert(inotify_unmap_path(pathref[3]) == 0);
|
||||||
|
|
||||||
assert(inotify_map_isempty());
|
assert(inotify_map_isempty());
|
||||||
|
|
|
||||||
Reference in a new issue