Exemple #1
0
/*
 * Removes the values referenced by an absolute registry pathname.
 *
 * Arguments:
 *      path            Pointer to a an absolute registry pathname.  Shall not
 *                      be NULL.  If the pathname refers to a node, then the
 *                      node and all its subnodes are recursively removed.
 *      quiet           Whether or not to be quiet about a pathname not
 *                      existing.
 * Returns:
 *      0               Success.
 *      NO_SUCH_ENTRY   No such entry in the registry.  "log_flush()" called iff
 *                      "quiet == 0".
 *      SYSTEM_ERROR    System error.  "log_flush()" called.
 */
static Status deletePath(
    const char* const   path,
    const int           quiet)
{
    log_debug("%s deleting path \"%s\"", quiet ? "Quietly" : "Non-quietly", path);

    switch (reg_deleteValue(path)) {
        case 0:
            return 0;

        case ENOENT: {
            RegNode*        node;

            switch (reg_getNode(path, &node, 0)) {
                case 0:
                    reg_deleteNode(node);

                    if (reg_flushNode(node)) {
                        log_flush_error();
                        return SYSTEM_ERROR;
                    }

                    return 0;
                case ENOENT:
                    if (!quiet) {
                        log_error("No such value or node: \"%s\"", path);
                    }
                    return NO_SUCH_ENTRY;
                default:
                    log_flush_error();
                    return SYSTEM_ERROR;
            }
        }
        /* FALLTHROUGH */
        /* no break */

        default:
            log_flush_error();
            return SYSTEM_ERROR;
    }
}
Exemple #2
0
static void
test_regDelete(void)
{
    RegStatus   status;
    char*       string;
    int         value;

    status = reg_putString("/string_key", "string value");
    if (status) {
        log_error("test_regDelete(): Couldn't put string");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getString("/string_key", &string);
    if (status) {
        log_error("test_regDelete(): Couldn't get string");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
        CU_ASSERT_STRING_EQUAL(string, "string value");
        free(string);
    }

    status = reg_deleteValue("/string_key");
    if (status) {
        log_error("test_regDelete(): Couldn't delete string");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getString("/string_key", &string);
    if (status && ENOENT != status) {
        log_error("test_regDelete(): Couldn't verify string deletion");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_putUint("/int_key", -1);
    if (status) {
        log_error("test_regDelete(): Couldn't put int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getUint("/int_key", &value);
    if (status) {
        log_error("test_regDelete(): Couldn't get int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
        CU_ASSERT_EQUAL(value, -1);
    }

    status = reg_deleteValue("/int_key");
    if (status) {
        log_error("test_regDelete(): Couldn't delete int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getUint("/int_key", &value);
    if (status && ENOENT != status) {
        log_error("test_regDelete(): Couldn't verify int deletion");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_deleteValue("/nosuch_key");
    if (status && ENOENT != status) {
        log_error("test_regDelete(): Couldn't verify no-such-value deletion");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }
}