Hello,
First of all i wanted to share with you my first ever patch, not just
for Augeas but in general too. This patch includes aug_find_lense a
function to find which lense was used for loading the specific file
given as a parameter (path) to augeas.
The augtool will have a command merge, I have done basic things on it
thought and it is not ready yet to show it. The command will work like this
merge destination merging-parameters files-to-be-merged
example:
merge /etc/hosts/ (merging-parameters) /tmp/myfile1 /tmp/myfile2 .....
/tmp/myfile3
By using the aug_find lense we can locate the lense used for the
destination file and then we can continue, and use it to load the
files-to-merged to augeas. Then after having them as a tree too there
will be a method aug_process_tree that will try to match the destination
with the files-to-be-merged, and will then call the right function
according to merging-parameters if a match is found.
The aug_process_tree function will be like
int aug_process_trees(struct augeas *aug, const char *dest, void
(*process)(struct augeas *aug, const char *first, const char *second, void*
data), void* data,const char *sources,...);
Anyway this is just a small report, on the things i am working. Feedback is
more than welcome.
Regards,
Christos
>From 248ea90591198943c9bd2b7a273168db95e47951 Mon Sep 17 00:00:00 2001
From: Christos Bountalis <[email protected]>
Date: Thu, 9 Jun 2011 17:47:29 +0300
Subject: [PATCH] Added aug_find_lense function to find and return used for loading a
specific file
Aug_find_lense is a function that accepts a path of a file, and tries to
find the lense that was used to load this file in Augeas. Returns either
a string representing the lense if it is located succesfully either null
if the lense could not be found, or the file is not loaded in augeas.
---
src/augeas.c | 25 +++++++++++++++++++++++++
src/augeas.h | 12 ++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/src/augeas.c b/src/augeas.c
index 88d151f..559bd49 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -617,6 +617,31 @@ static int find_one_node(struct pathx *p, struct tree **match) {
return -1;
}
+char* aug_find_lense(struct augeas *aug,const char *path){
+ //creating a path to run with aug_match in order to find the lense used
+ //so it can use the same lense to load the other n number paths ...
+ char *startstr="/augeas/load/*[ '";
+ char *endstr="/' =~ glob(incl) + regexp('/.*') ]/lens";
+ char *tempstr=malloc((strlen(startstr)+strlen(endstr)+strlen(path)+2)*sizeof(char));
+ sprintf(tempstr,"%s%s%s",startstr,path,endstr);
+ //proceed with running the match path for the lense
+ int cnt;
+ char **matches;
+ cnt=aug_match(aug,tempstr,&matches);
+ if (cnt != 1) {
+ printf("Error locating the lense for the specific path\n");
+ free(tempstr);
+ return NULL;
+ }else{
+ char *val;
+ aug_get(aug, matches[0], &val);
+ //remove initial @
+ *val=*val++;
+ free(tempstr);
+ return val;
+ }
+}
+
int aug_get(const struct augeas *aug, const char *path, const char **value) {
struct pathx *p = NULL;
struct tree *match;
diff --git a/src/augeas.h b/src/augeas.h
index 813b7a6..af387ff 100644
--- a/src/augeas.h
+++ b/src/augeas.h
@@ -192,6 +192,18 @@ int aug_insert(augeas *aug, const char *path, const char *label, int before);
*/
int aug_rm(augeas *aug, const char *path);
+/* Function: aug_find_lense
+ *
+ * Finds the lense used for loading the file given as path
+ * to Augeas tree
+ *
+ * Returns:
+ * The lense name, or null if the detection was not possible
+ */
+
+char* aug_find_lense(struct augeas *aug,const char *path);
+
+
/* Function: aug_mv
*
* Move the node SRC to DST. SRC must match exactly one node in the
--
1.7.3.4
_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel