/* Check that defining a variable with defnode leads to a corresponding * entry in /augeas/variables and that that entry disappears when the * variable is undefined */ static void testDefNodeCreateMeta(CuTest *tc) { int r, created; struct augeas *aug; static const char *const expr = "/augeas/version/save/mode[last()+1]"; static const char *const expr_can = "/augeas/version/save/mode[5]"; const char *value; aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD); CuAssertPtrNotNull(tc, aug); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); r = aug_defnode(aug, "var", expr, "other", &created); CuAssertIntEquals(tc, 1, r); CuAssertIntEquals(tc, 1, created); r = aug_match(aug, "/augeas/variables/*", NULL); CuAssertIntEquals(tc, 1, r); r = aug_get(aug, "/augeas/variables/var", &value); CuAssertStrEquals(tc, expr_can, value); r = aug_defvar(aug, "var", NULL); CuAssertIntEquals(tc, 0, r); r = aug_match(aug, "/augeas/variables/*", NULL); CuAssertIntEquals(tc, 0, r); aug_close(aug); }
static int Paug_defnode(lua_State *L) { augeas *a = Paug_checkarg(L, 1); const char *name = luaL_checkstring(L, 2); const char *expr = luaL_checkstring(L, 3); const char *value = luaL_checkstring(L, 4); return pushresult(L, aug_defnode(a, name, expr, value, NULL), a, NULL); }
/* * call-seq: * defnode(NAME, EXPR, VALUE) -> boolean * * Define a variable NAME whose value is the result of evaluating EXPR, * which must be non-NULL and evaluate to a nodeset. If a variable NAME * already exists, its name will be replaced with the result of evaluating * EXPR. * * If EXPR evaluates to an empty nodeset, a node is created, equivalent to * calling AUG_SET(AUG, EXPR, VALUE) and NAME will be the nodeset containing * that single node. * * Returns +false+ if +aug_defnode+ fails, and the number of nodes in the * nodeset on success. */ VALUE augeas_defnode(VALUE s, VALUE name, VALUE expr, VALUE value) { augeas *aug = aug_handle(s); const char *cname = StringValueCStr(name); const char *cexpr = StringValueCStrOrNull(expr); const char *cvalue = StringValueCStrOrNull(value); /* FIXME: Figure out a way to return created, maybe accept a block that gets run when created == 1 ? */ int r = aug_defnode(aug, cname, cexpr, cvalue, NULL); return (r < 0) ? Qfalse : INT2NUM(r); }
guestfs_int_int_bool * do_aug_defnode (const char *name, const char *expr, const char *val) { #ifdef HAVE_AUG_DEFNODE static guestfs_int_int_bool r; int created; NEED_AUG (NULL); r.i = aug_defnode (aug, name, expr, val, &created); if (r.i == -1) { reply_with_error ("Augeas defnode failed"); return NULL; } r.b = created; return &r; #else NOT_AVAILABLE (NULL); #endif }