summaryrefslogtreecommitdiff
path: root/src/set.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set.c')
-rw-r--r--src/set.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/set.c b/src/set.c
index 9be3fc8..47db90c 100644
--- a/src/set.c
+++ b/src/set.c
@@ -91,6 +91,63 @@ boolean set_validate(vtw_def *defp, char *valp, boolean empty_val)
}
return TRUE;
}
+
+ //apply limit count here, needs to be defined as a tag,multi and have a value set
+ if ((defp->tag || defp->multi) && (defp->def_tag > 0 || defp->def_multi > 0)) {
+ //get count of siblings
+
+ char path[2048];
+ char val[2048];
+ char last_val[2048];
+ char *pos = rindex(m_path.path,'/');
+ if (pos != NULL) {
+ int offset = pos - m_path.path;
+
+ strncpy(path,m_path.path,offset);
+ path[offset] = '\0';
+
+ strncpy(val,m_path.path + offset + 1, strlen(m_path.path) - offset - 1);
+ val[strlen(m_path.path) - offset - 1] = '\0';
+
+ // fprintf(out_stream,"val: %s, offset: %d, path: %s\n",val,offset,m_path.path);
+
+ int file_count = 0;
+ struct dirent* entry;
+ DIR* dirp = opendir(path); /* There should be error handling after this */
+ if (dirp != NULL) {
+ while ((entry = readdir(dirp)) != NULL) {
+ if (strcmp(entry->d_name,".") != 0 &&
+ strcmp(entry->d_name,"..") != 0) {
+ strcpy(last_val,entry->d_name);
+ file_count++;
+ }
+ }
+ closedir(dirp);
+
+ if (defp->tag && file_count == 1 && defp->def_tag == 1) {
+ //this is the special case, where the previous value should be deleted here...
+ char command[8192];
+ //let unionfs handle the diff
+ sprintf(command, "mv %s/%s %s/%s", path,last_val,path,val);
+ system(command);
+ }
+
+ if (defp->tag) {
+ if (defp->def_tag > 1 && file_count >= defp->def_tag) {
+ fprintf(out_stream,"Number of values exceeded for %s, allowed: %d, actual: %d\n",val,defp->def_tag,file_count);
+ return FALSE;
+ }
+ }
+ else {
+ if (defp->def_multi > 1 && file_count >= defp->def_multi) {
+ fprintf(out_stream,"Number of values exceeded for %s, allowed: %d, actual: %d\n",val,defp->def_multi,file_count);
+ return FALSE;
+ }
+ }
+ }
+ }
+ }
+
res = validate_value(defp, valp);
return res;
}