[augeas-devel] augeas: master - Record saved files in transform_save, not tree_save
David Lutterkort
lutter at fedoraproject.org
Thu Feb 26 23:43:30 UTC 2009
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=cbe2f82b7d2c81b0e4cb2a0f2be99b04cb5143bb
Commit: cbe2f82b7d2c81b0e4cb2a0f2be99b04cb5143bb
Parent: 61aa8b04d0035a07a73f3c91f5749e68af5d3249
Author: David Lutterkort <lutter at redhat.com>
AuthorDate: Tue Feb 24 22:20:29 2009 -0800
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Tue Feb 24 22:20:29 2009 -0800
Record saved files in transform_save, not tree_save
---
src/augeas.c | 24 ++++--------------------
src/transform.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/src/augeas.c b/src/augeas.c
index 5d6a599..f05dc95 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -599,8 +599,8 @@ int aug_match(const struct augeas *aug, const char *pathin, char ***matches) {
return -1;
}
-static int tree_save(struct augeas *aug, struct tree *tree, const char *path,
- int *count) {
+static int tree_save(struct augeas *aug, struct tree *tree,
+ const char *path) {
int result = 0;
// FIXME: We need to detect subtrees that aren't saved by anything
aug_rm(aug, AUGEAS_EVENTS_SAVED);
@@ -630,23 +630,8 @@ static int tree_save(struct augeas *aug, struct tree *tree, const char *path,
int r = transform_save(aug, transform, tpath, t);
if (r == -1)
result = -1;
- else if (r > 0) {
- char *sp;
- *count += 1;
- if (asprintf(&sp, AUGEAS_EVENTS_SAVED "[%d]",
- *count) < 0) {
- free(tpath);
- return -1;
- }
- if (aug_set(aug, sp, tpath) < 0) {
- free(tpath);
- free(sp);
- return -1;
- }
- free(sp);
- }
} else {
- if (tree_save(aug, t->children, tpath, count) == -1)
+ if (tree_save(aug, t->children, tpath) == -1)
result = -1;
}
free(tpath);
@@ -699,9 +684,8 @@ int aug_save(struct augeas *aug) {
tree_propagate_dirty(t);
}
if (files->dirty) {
- int count = 0;
list_for_each(t, files->children) {
- if (tree_save(aug, t, AUGEAS_FILES_TREE, &count) == -1)
+ if (tree_save(aug, t, AUGEAS_FILES_TREE) == -1)
ret = -1;
}
}
diff --git a/src/transform.c b/src/transform.c
index 847e43c..bc91668 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -520,6 +520,32 @@ static char *strappend(const char *s1, const char *s2) {
return result;
}
+static int file_saved_event(struct augeas *aug, const char *path) {
+ const char *saved = strrchr(AUGEAS_EVENTS_SAVED, SEP) + 1;
+ struct pathx *px;
+ struct tree *dummy;
+ int r;
+
+ r = pathx_parse(aug->origin, AUGEAS_EVENTS_SAVED "[last()]", &px);
+ if (r != PATHX_NOERROR)
+ return -1;
+
+ if (pathx_find_one(px, &dummy) == 1) {
+ r = tree_insert(px, saved, 0);
+ if (r < 0)
+ goto error;
+ }
+
+ if (! tree_set(px, path))
+ goto error;
+
+ free_pathx(px);
+ return 0;
+ error:
+ free_pathx(px);
+ return -1;
+}
+
/*
* Save TREE->CHILDREN into the file PATH using the lens from XFORM. Errors
* are noted in the /augeas/files hierarchy in AUG->ORIGIN under
@@ -654,6 +680,13 @@ int transform_save(struct augeas *aug, struct transform *xform,
result = 1;
done:
+ if (result > 0) {
+ r = file_saved_event(aug, path);
+ if (r < 0) {
+ err_status = "saved_event";
+ result = -1;
+ }
+ }
{
const char *emsg =
dyn_err_status == NULL ? err_status : dyn_err_status;
More information about the augeas-devel
mailing list