summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli_val_engine.c12
-rw-r--r--src/delete.c88
2 files changed, 94 insertions, 6 deletions
diff --git a/src/cli_val_engine.c b/src/cli_val_engine.c
index adf40a4..786c0cd 100644
--- a/src/cli_val_engine.c
+++ b/src/cli_val_engine.c
@@ -217,10 +217,12 @@ static char** clind_get_current_value(clind_path_ref cfg_path,
struct stat statbuf;
/* Directory reference: */
- if(!check_existence || (lstat(cfg_path_string, &statbuf) == 0)) {
- ret=(char**)realloc(ret,sizeof(char*)*1);
- ret[0]=clind_unescape(cfg_end);
- *ret_size=1;
+ if(!check_existence) {
+ if (lstat(cfg_path_string, &statbuf) == 0) {
+ ret=(char**)realloc(ret,sizeof(char*)*1);
+ ret[0]=clind_unescape(cfg_end);
+ *ret_size=1;
+ }
} else {
/* we are checking existence, and it doesn't exist */
/* return empty string */
@@ -230,7 +232,7 @@ static char** clind_get_current_value(clind_path_ref cfg_path,
*ret_size = 1;
}
}
-
+
if(ret) {
if(tmpl_end && (strcmp(tmpl_end,NODE_TAG)==0)) {
/* since it's a tag, it should be treated as a value */
diff --git a/src/delete.c b/src/delete.c
index bb36fd1..aa83796 100644
--- a/src/delete.c
+++ b/src/delete.c
@@ -34,6 +34,49 @@ static void remove_rf(boolean do_umount)
free(command);
}
}
+static boolean has_default(char **def, int size)
+{
+ char *buf;
+ buf = malloc(1025);
+ char *buf_ptr;
+ FILE *fp = fopen(t_path.path, "r");
+ if (fp) {
+ while (fgets(buf, 1024, fp)) {
+ if (strncmp(buf, "default:", 8) == 0) {
+ buf_ptr = index(buf,':');
+ if (buf_ptr == NULL) {
+ break;
+ }
+ buf_ptr++;
+ if (size < strlen(buf_ptr)-1) {
+ bye("default buffer size is too small\n");
+ }
+ memcpy(*def, buf_ptr, strlen(buf_ptr)-1);
+ fclose(fp);
+ free(buf);
+ return 0;
+ }
+ }
+ fclose(fp);
+ }
+ free(buf);
+ return 1;
+}
+static void reset_default(char *def_val)
+{
+ char *command;
+ boolean has_default = 1;
+ if (def_val == NULL) {
+ return;
+ }
+ if (has_default) {
+ touch();
+ command = my_malloc(strlen(m_path.path) + 100, "set");
+ sprintf(command, "echo %s > %s/node.val", def_val, m_path.path);
+ system(command);
+ free(command);
+ }
+}
/***************************************************
set_validate:
validate value against definition
@@ -139,6 +182,7 @@ int main(int argc, char **argv)
fprintf(out_stream, "Nothing to delete\n");
bye("Nothing to delete at %s", m_path.path);
}
+
remove_rf(FALSE);
pop_path(&m_path);
if ((dp = opendir(m_path.path)) == NULL){
@@ -187,7 +231,17 @@ int main(int argc, char **argv)
}
}
/* else no defnition, remove it also */
- remove_rf(FALSE);
+ char *def_val;
+ def_val = malloc(1025);
+ if (has_default(&def_val,1024) == 0) {
+ reset_default(def_val);
+ free(def_val);
+ }
+ else {
+ remove_rf(FALSE);
+ }
+
+ // remove_rf(FALSE);
exit(0);
}
if(ai < argc -1 || last_tag) {
@@ -267,6 +321,38 @@ int main(int argc, char **argv)
remove_rf(FALSE);
return 0;
}
+
+ /*
+ let's do a new check here:
+ -> if this is a leaf and there is a value look for a match of the value
+ -> make sure to check existing configuration as well as uncommitted config
+ */
+ if (ai+1 == argc) {
+ //does this work up until the last value
+ pop_path(&m_path);
+ if(lstat(m_path.path, &statbuf) == 0) {
+ //now compare last value with that in the node.def file to determine whether to accept this delete
+ status = get_value(&cp, &m_path);
+ if (status != VTWERR_OK) {
+ bye("Cannot read old value %s\n", m_path.path);
+ }
+ if (!strcmp(cp,argv[argc - 1])) {
+ /* Also need to handle the case where the value is not specified. */
+ char *def_val;
+ def_val = malloc(1025);
+ if (has_default(&def_val,1024) == 0) {
+ reset_default(def_val);
+ free(def_val);
+ }
+ else {
+ remove_rf(FALSE);
+ }
+ return 0;
+ }
+ }
+ }
+
+
fprintf(out_stream, "The specified configuration node is not valid\n");
bye("There is no appropriate template for %s",
m_path.path + strlen(get_mdirp()));