uci: add rpc_uci_replace_savedir() helper
The rpc_uci_replace_savedir() function removes all configured save directories from the uci cursor instance and adds the given path argument as sole item. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
eb09f3a3fd
commit
edd37f8dbb
1 changed files with 19 additions and 7 deletions
26
uci.c
26
uci.c
|
@ -204,15 +204,13 @@ rpc_uci_status(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup per-session delta save directory. If the passed "sid" blob attribute
|
* Clear all save directories from the uci cursor and append the given path
|
||||||
* pointer is NULL then the precedure was not invoked through the ubus-rpc so
|
* as new save directory.
|
||||||
* we do not perform session isolation and use the default save directory.
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
rpc_uci_set_savedir(struct blob_attr *sid)
|
rpc_uci_replace_savedir(const char *path)
|
||||||
{
|
{
|
||||||
struct uci_element *e, *tmp;
|
struct uci_element *e, *tmp;
|
||||||
char path[PATH_MAX];
|
|
||||||
|
|
||||||
uci_foreach_element_safe(&cursor->delta_path, tmp, e)
|
uci_foreach_element_safe(&cursor->delta_path, tmp, e)
|
||||||
free(e);
|
free(e);
|
||||||
|
@ -220,16 +218,30 @@ rpc_uci_set_savedir(struct blob_attr *sid)
|
||||||
cursor->delta_path.prev = &cursor->delta_path;
|
cursor->delta_path.prev = &cursor->delta_path;
|
||||||
cursor->delta_path.next = &cursor->delta_path;
|
cursor->delta_path.next = &cursor->delta_path;
|
||||||
|
|
||||||
|
if (path)
|
||||||
|
uci_set_savedir(cursor, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Setup per-session delta save directory. If the passed "sid" blob attribute
|
||||||
|
* pointer is NULL then the precedure was not invoked through the ubus-rpc so
|
||||||
|
* we do not perform session isolation and use the default save directory.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
rpc_uci_set_savedir(struct blob_attr *sid)
|
||||||
|
{
|
||||||
|
char path[PATH_MAX];
|
||||||
|
|
||||||
if (!sid)
|
if (!sid)
|
||||||
{
|
{
|
||||||
uci_set_savedir(cursor, "/tmp/.uci");
|
rpc_uci_replace_savedir("/tmp/.uci");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(path, sizeof(path) - 1,
|
snprintf(path, sizeof(path) - 1,
|
||||||
RPC_UCI_SAVEDIR_PREFIX "%s", blobmsg_get_string(sid));
|
RPC_UCI_SAVEDIR_PREFIX "%s", blobmsg_get_string(sid));
|
||||||
|
|
||||||
uci_set_savedir(cursor, path);
|
rpc_uci_replace_savedir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue