46 int uploadtree_pk,
int skipProcessedCheck,
49 char *fcnName =
"walkTree";
51 PGresult *result, *origresult;
52 int numChildren, childIdx;
54 int bucketpool_pk = bucketDefArray->bucketpool_pk;
58 if (
debug) printf(
"---- START walkTree, uploadtree_pk=%d ----\n",uploadtree_pk);
61 sprintf(sqlbuf,
"select pfile_fk, lft, rgt, ufile_mode, ufile_name, upload_fk from %s where uploadtree_pk=%d",
62 bucketDefArray->uploadtree_tablename, uploadtree_pk);
63 origresult = PQexec(pgConn, sqlbuf);
64 if (
fo_checkPQresult(pgConn, origresult, sqlbuf, fcnName, __LINE__))
return -1;
65 if (PQntuples(origresult) == 0)
67 printf(
"FATAL: %s.%s missing uploadtree_pk %d\n", __FILE__, fcnName, uploadtree_pk);
71 uploadtree.
pfile_fk = atol(PQgetvalue(origresult, 0, 0));
72 uploadtree.
lft = atol(PQgetvalue(origresult, 0, 1));
73 uploadtree.
rgt = atol(PQgetvalue(origresult, 0, 2));
74 uploadtree.
ufile_mode = atol(PQgetvalue(origresult, 0, 3));
75 uploadtree.
ufile_name = strdup(PQgetvalue(origresult, 0, 4));
76 uploadtree.
upload_fk = atol(PQgetvalue(origresult, 0, 5));
78 if (!skipProcessedCheck)
86 if (uploadtree.
rgt == (uploadtree.
lft+1))
88 return processFile(pgConn, bucketDefArray, &uploadtree, agent_pk, hasPrules);
95 sprintf(sqlbuf,
"select uploadtree_pk,pfile_fk, lft, rgt, ufile_mode, ufile_name from %s where parent=%d",
96 bucketDefArray->uploadtree_tablename, uploadtree_pk);
97 result = PQexec(pgConn, sqlbuf);
99 numChildren = PQntuples(result);
100 if (numChildren == 0)
102 printf(
"FATAL: %s.%s: Inconsistent uploadtree. uploadtree_pk %d should have children based on lft and rgt\n",
103 __FILE__, fcnName, uploadtree_pk);
108 for (childIdx = 0; childIdx < numChildren; childIdx++)
110 childuploadtree.
uploadtree_pk = atol(PQgetvalue(result, childIdx, 0));
111 childuploadtree.
pfile_fk = atol(PQgetvalue(result, childIdx, 1));
114 childuploadtree.
lft = atoi(PQgetvalue(result, childIdx, 2));
115 childuploadtree.
rgt = atoi(PQgetvalue(result, childIdx, 3));
116 childuploadtree.
ufile_mode = atoi(PQgetvalue(result, childIdx, 4));
117 childuploadtree.
ufile_name = strdup(PQgetvalue(result, childIdx, 5));
122 if (childuploadtree.
rgt == (childuploadtree.
lft+1))
125 processFile(pgConn, bucketDefArray, &childuploadtree,
126 agent_pk, hasPrules);
141 processFile(pgConn, bucketDefArray, &childuploadtree, agent_pk,
184 char *fcnName =
"processFile";
193 && (puploadtree->
rgt == puploadtree->
lft+1))
return 0;
210 snprintf(sql,
sizeof(sql),
211 "select pkg_name, version, '' as vendor, source as srcpkg from pkg_deb where pfile_fk='%d' \ 213 select pkg_name, version, vendor, source_rpm as srcpkg from pkg_rpm where pfile_fk='%d' ",
215 result = PQexec(pgConn, sql);
217 isPkg = PQntuples(result);
225 strncpy(package.
pkgname, PQgetvalue(result, 0, 0),
sizeof(package.
pkgname)-1);
230 strncpy(package.
pkgvers, PQgetvalue(result, 0, 1),
sizeof(package.
pkgvers)-1);
235 strncpy(package.
vendor, PQgetvalue(result, 0, 2),
sizeof(package.
vendor)-1);
260 agent_pk, bucketDefArray->
nomos_agent_pk, bucketDefArray->bucketpool_pk);
261 if (bucketList) free(bucketList);
264 rv =
processLeaf(pgConn, bucketDefArray, puploadtree, &package,
265 agent_pk, hasPrules);
269 rv =
processLeaf(pgConn, bucketDefArray, puploadtree, &package,
270 agent_pk, hasPrules);
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
PGconn * pgConn
Database connection.
FUNCTION int processFile(PGconn *pgConn, pbucketdef_t bucketDefArray, puploadtree_t puploadtree, int agent_pk, int hasPrules)
Process a file.
FUNCTION int writeBuckets(PGconn *pgConn, int pfile_pk, int uploadtree_pk, int *bucketList, int agent_pk, int nomosagent_pk, int bucketpool_pk)
Write bucket results to either db (bucket_file, bucket_container) or stdout.
Contains information required by uploadtree elements.
FUNCTION int processLeaf(PGconn *pgConn, pbucketdef_t bucketDefArray, puploadtree_t puploadtree, ppackage_t ppackage, int agent_pk, int hasPrules)
Determine which bucket(s) a leaf node is in and write results.
FUNCTION int * getContainerBuckets(PGconn *pgConn, pbucketdef_t bucketDefArray, int uploadtree_pk)
Given a container uploadtree_pk and bucketdef, determine what buckets the container is in...
FUNCTION int walkTree(PGconn *pgConn, pbucketdef_t bucketDefArray, int agent_pk, int uploadtree_pk, int skipProcessedCheck, int hasPrules)
This function does a recursive depth first walk through a file tree (uploadtree). ...
FUNCTION int processed(PGconn *pgConn, int agent_pk, int nomos_agent_pk, int pfile_pk, int uploadtree_pk, int bucketpool_pk, int bucket_pk)
Has this pfile or uploadtree_pk already been bucket processed? This only works if the bucket has been...