From ddb5964c07ecd9f14ca4896af47ed5c85a72558c Mon Sep 17 00:00:00 2001 From: Krzysztof Opasiak Date: Tue, 14 Apr 2015 12:26:42 +0200 Subject: libusbg: Add rm callback to usbg_function Some functions requires more complicated rm method which will remove its sub directories. To avoid complexity in usbg_rm_function() just add a callback which is called there. Signed-off-by: Krzysztof Opasiak Reviewed-by: Pawel Szewczyk --- include/usbg/usbg_internal.h | 3 +++ src/usbg.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/usbg/usbg_internal.h b/include/usbg/usbg_internal.h index 793319c..30098c9 100644 --- a/include/usbg/usbg_internal.h +++ b/include/usbg/usbg_internal.h @@ -74,6 +74,8 @@ struct usbg_config int id; }; +typedef int (*usbg_rm_function_callback)(usbg_function *, int); + struct usbg_function { TAILQ_ENTRY(usbg_function) fnode; @@ -85,6 +87,7 @@ struct usbg_function /* Only for internal library usage */ char *label; usbg_function_type type; + usbg_rm_function_callback rm_callback; }; struct usbg_binding diff --git a/src/usbg.c b/src/usbg.c index 0b96524..9182acb 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -725,6 +725,13 @@ static usbg_function *usbg_allocate_function(const char *path, f->parent = parent; f->type = type; + /* only composed funcitons (with subdirs) require this callback */ + switch (usbg_lookup_function_attrs_type(type)) { + default: + f->rm_callback = NULL; + break; + } + if (!(f->path)) { free(f->name); free(f->path); @@ -1642,12 +1649,19 @@ int usbg_rm_function(usbg_function *f, int opts) } /* TAILQ_FOREACH */ } + if (f->rm_callback) { + ret = f->rm_callback(f, opts); + if (ret != USBG_SUCCESS) + goto out; + } + ret = usbg_rm_dir(f->path, f->name); if (ret == USBG_SUCCESS) { TAILQ_REMOVE(&(g->functions), f, fnode); usbg_free_function(f); } +out: return ret; } -- cgit v1.2.3