summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
authorMichael Larson <slioch@eng-140.vyatta.com>2008-04-14 17:35:55 -0700
committerMichael Larson <slioch@eng-140.vyatta.com>2008-04-14 17:35:55 -0700
commit043d8925a06ad6a6ac01939b263d474a31721352 (patch)
treeac7e715fc1a1c97495a1bacaebd567900e671eae /src/commit.c
parentc59e8b9812d7795d96a07db879a5626f4f1d2e7a (diff)
downloadvyatta-cfg-043d8925a06ad6a6ac01939b263d474a31721352.tar.gz
vyatta-cfg-043d8925a06ad6a6ac01939b263d474a31721352.zip
modified node ordering code.
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c72
1 files changed, 24 insertions, 48 deletions
diff --git a/src/commit.c b/src/commit.c
index 84e088f..c0051a2 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -26,11 +26,6 @@ struct DirSort {
unsigned long priority;
};
-/*
-static int g_dirname_index = 0;
-static int g_dirname_ct = 0;
-static struct DirSort** g_dirname = NULL;
-*/
static char def_name[] = DEF_NAME;
static char tag_name[] = TAG_NAME;
@@ -69,7 +64,7 @@ static void make_dir()
return;
}
#endif
-/*
+
static int
compare_dirname(const void *p, const void *q)
{
@@ -81,18 +76,14 @@ compare_dirname(const void *p, const void *q)
return ((long)b->priority - (long)a->priority);
}
-void
-init_next_filtered_dirname(DIR *dp, struct DirIndex *di, int exclude_wh)
+struct DirIndex*
+init_next_filtered_dirname(DIR *dp, int exclude_wh)
{
- // fprintf(out_stream,"\n");
+ struct DirIndex *di = malloc(sizeof(struct DirIndex));
di->dirname = malloc(1024 * sizeof(char*));
di->dirname_ct = 0;
di->dirname_index = 0;
- int i;
-
- //NOTE: need to free ct round up to next 1024 when shutting down commit
-
struct dirent *dirp;
while ((dirp = readdir(dp)) != NULL) {
if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0
@@ -108,23 +99,19 @@ init_next_filtered_dirname(DIR *dp, struct DirIndex *di, int exclude_wh)
}
strcpy(d->name,dirp->d_name);
d->priority = (unsigned long)0;
-
- //retreive priority now
vtw_def def;
char *path;
- path = malloc(strlen(t_path.path)+strlen(dirp->d_name)+2+8);
+ path = malloc(strlen(t_path.path)+strlen(dirp->d_name)+2+8+1);
sprintf(path,"%s/%s/node.def",t_path.path,dirp->d_name);
struct stat s;
if ((lstat(path,&s) >= 0) &&
((s.st_mode & S_IFMT) == S_IFREG)) {
memset(&def, 0, sizeof(def));
if (parse_def(&def,path,FALSE) == 0) {
- // fprintf(out_stream, "found(D): %s:%d\n",dirp->d_name, def.def_priority);
d->priority = def.def_priority;
}
}
free(path);
-
di->dirname[di->dirname_ct++] = d;
if (di->dirname_ct % 1024 == 0) {
di->dirname = realloc(di->dirname, (di->dirname_ct+1024)*sizeof(char*));
@@ -132,34 +119,31 @@ init_next_filtered_dirname(DIR *dp, struct DirIndex *di, int exclude_wh)
}
}
qsort(di->dirname, di->dirname_ct, sizeof(char*), compare_dirname);
+ return di;
}
static char*
get_next_filtered_dirname(struct DirIndex *di)
{
- if (di->dirname_index == di->dirname_ct) {
+ if (di == NULL || di->dirname_index == di->dirname_ct) {
return NULL;
}
- //just return the collection ptr;
- // fprintf(out_stream, "get_next: %s\n", di->dirname[di->dirname_index]->name);
return di->dirname[di->dirname_index++]->name;
}
-*/
-static struct dirent *
-get_next_filtered_dirent(DIR *dp, int exclude_wh)
+
+void
+release_dir_index(struct DirIndex *di)
{
- struct dirent *dirp = NULL;
- while ((dirp = readdir(dp)) != NULL) {
- if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0
- || strcmp(dirp->d_name, MOD_NAME) == 0
- || strcmp(dirp->d_name, opaque_name) == 0
- || (exclude_wh && strncmp(dirp->d_name, ".wh.", 4) == 0)) {
- continue;
- } else {
- return dirp;
+ if (di != NULL) {
+ int i;
+ for (i = 0; i < di->dirname_ct; ++i) {
+ if (di->dirname[i] != NULL) {
+ free((struct DirSort*)di->dirname[i]);
+ }
}
+ free(di);
+ di = NULL;
}
- return dirp;
}
/*************************************************
@@ -180,7 +164,6 @@ static boolean validate_dir_for_commit()
boolean value_present=FALSE;
int subdirs_number=0;
DIR *dp=NULL;
- struct dirent *dirp=NULL;
char *dirname = NULL;
char *cp=NULL;
boolean ret=TRUE;
@@ -223,18 +206,14 @@ static boolean validate_dir_for_commit()
if (def_present && def.tag) {
push_path(&t_path, tag_name); /* PUSH 2a */
}
- /*
- struct DirIndex *di = malloc(sizeof(struct DirIndex));
- init_next_filtered_dirname(dp,di,1);
+ struct DirIndex *di = init_next_filtered_dirname(dp,1);
while ((dirname = get_next_filtered_dirname(di)) != NULL) {
- */
- while ((dirp = get_next_filtered_dirent(dp,1)) != NULL) {
subdirs_number++;
if(uename)
my_free(uename);
- uename = clind_unescape(dirp->d_name);
+ uename = clind_unescape(dirname);
if (strcmp(uename, VAL_NAME) == 0) {
@@ -348,6 +327,7 @@ static boolean validate_dir_for_commit()
pop_path(&t_path); /* for PUSH 2b */
} // while
+ release_dir_index(di);
status = closedir(dp);
if (status)
bye("Cannot close dir %s\n", m_path.path);
@@ -1061,18 +1041,14 @@ get_filtered_directory_listing(DIR *dp, valstruct *mvals, vtw_type_e type,
{
char *dname = NULL;
char *cp = NULL;
- struct dirent *dirp = NULL;
memset(mvals, 0, sizeof (valstruct));
- /*
- struct DirIndex *di = malloc(sizeof(struct DirIndex));
- init_next_filtered_dirname(dp,di,exclude_wh);
+ struct DirIndex *di = init_next_filtered_dirname(dp,exclude_wh);
while ((dname = get_next_filtered_dirname(di)) != NULL) {
- */
- while ((dirp = get_next_filtered_dirent(dp,exclude_wh)) != NULL) {
- cp = clind_unescape(dirp->d_name);
+ cp = clind_unescape(dname);
valstruct_append(mvals, cp, type);
}
+ release_dir_index(di);
}
/* check if a value is one of those in a valstruct.