src/plugins/augeas/augeas.c
/**
 * 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.
 */
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.
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 (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;
}
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 , " " , treePath ) ; if ( result < 0 ) return -1 ; int numChildNodes = aug_match ( handle , nodeMatch , & matches ) ; elektraFree ( nodeMatch ) ; 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 ; }
Checks whether a given path must be pruned from the Augeas tree by comparing
 it with the supplied keyset.
Checks whether a given path must be pruned from the Augeas tree by comparing it with the supplied keyset .
/* if the node is a leaf node we can safely delete it */