예제 #1
0
/**
 * Checks whether a given path must be pruned from the Augeas tree by comparing
 * it with the supplied keyset. If any operation during pruning fails, an error
 * is returned in order to prevent invalid keys.
 */
static int removeOrphan (augeas * handle, const char * treePath, void * data)
{
	int result;
	struct OrphanSearch * orphanData = (struct OrphanSearch *)data;

	Key * key = createKeyFromPath (orphanData->parentKey, treePath);

	if (!ksLookup (orphanData->ks, key, KDB_O_NONE))
	{
		char * nodeMatch;
		char ** matches;
		result = asprintf (&nodeMatch, "%s/*", treePath);

		if (result < 0) return -1;

		int numChildNodes = aug_match (handle, nodeMatch, &matches);
		elektraFree (nodeMatch);

		/* if the node is a leaf node we can safely delete it */
		if (numChildNodes == 0)
		{
			aug_rm (handle, treePath);
		}
		else
		{
			short pruneTree = 1;
			for (int i = 0; i < numChildNodes; i++)
			{
				Key * childKey = createKeyFromPath (orphanData->parentKey, matches[i]);
				if (ksLookup (orphanData->ks, childKey, KDB_O_NONE))
				{
					pruneTree = 0;
				}
				keyDel (childKey);
				elektraFree (matches[i]);
			}
			elektraFree (matches);

			if (pruneTree)
			{
				aug_rm (handle, treePath);
			}
		}
	}

	keyDel (key);

	return 0;
}
예제 #2
0
파일: augeas.c 프로젝트: beku/libelektra
static int convertToKey(augeas *handle, const char *treePath, void *data)
{
	struct KeyConversion *conversionData = (struct KeyConversion *) data;
	int result = 0;
	const char *value = 0;
	result = aug_get (handle, treePath, &value);

	if (result < 0) return result;

	Key *key = createKeyFromPath (conversionData->parentKey, treePath);

	/* fill key values */
	keySetString (key, value);
	conversionData->currentOrder++;
	keySetOrderMeta (key, conversionData->currentOrder);
	result = ksAppendKey (conversionData->ks, key);

	return result;
}
예제 #3
0
/**
 * Creates a new Elektra key from the specified Augeas key.
 * If any step during key conversion fails, an error is returned
 * in order to prevent inconsistent keys.
 */
static int convertToKey (augeas * handle, const char * treePath, void * data)
{
	struct KeyConversion * conversionData = (struct KeyConversion *)data;
	int result = 0;
	const char * value = 0;
	result = aug_get (handle, treePath, &value);

	/* we were unable to retrieve the augeas value */
	if (result < 0) return result;

	Key * key = createKeyFromPath (conversionData->parentKey, treePath);

	/* fill key values */
	keySetString (key, value);
	conversionData->currentOrder++;
	result = keySetOrderMeta (key, conversionData->currentOrder);

	/* setting the correct key order failed */
	if (result < 0) return result;

	result = ksAppendKey (conversionData->ks, key);

	return result;
}