src/hg/lib/customFactory.c 1.105

1.105 2009/10/08 03:33:26 angie
A little code cleanup: removed vestigial save/restore of env vars, improved a couple warning messages, replaced dangerous use of stack variable outside its scope w/dyString, removed some unnecessary uses of dyString.
Index: src/hg/lib/customFactory.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/customFactory.c,v
retrieving revision 1.104
retrieving revision 1.105
diff -b -B -U 4 -r1.104 -r1.105
--- src/hg/lib/customFactory.c	23 Sep 2009 18:42:20 -0000	1.104
+++ src/hg/lib/customFactory.c	8 Oct 2009 03:33:26 -0000	1.105
@@ -64,46 +64,10 @@
 /* Make sure it's a chromosome or a contig.  Well, at the moment,
  * just make sure it's a chromosome. */
 {
 if (!hgIsOfficialChromName(genomeDb, word))
-    lineFileAbort(lf, "%s not a chromosome (note: chrom names are case sensitive)", word);
-}
-
-static char *saveConf = NULL;
-
-static void saveCurrentEnv()
-/* while fiddling with environment for pipeline loaders, remember previous env
- */
-{
-char *val = NULL;
-freez(&saveConf);	/* clear these if previously used	*/
-val = getenv("HGDB_CONF");
-if (!isEmpty(val))
-    saveConf = cloneString(val);
-}
-
-static void restorePrevEnv()
-/* while fiddling with environment for pipeline loaders, restore environment */
-{
-/* can not eliminate the variables from the environment, but can make
- * them be empty strings.  This will be good enough for cfgOptionEnv()
- * in hdb.c and jksql.c
- */
-if (saveConf != NULL)
-    envUpdate("HGDB_HOST", saveConf);
-else
-    envUpdate("HGDB_HOST", "");
-freez(&saveConf);
-}
-
-char *customTrackTempDb()
-/* Get custom database.  If first time set up some
- * environment variables that the loaders will need. */
-{
-/* set environment for pipeline commands, but don't override if
- * already set for debugging. */
-saveCurrentEnv();
-return (CUSTOM_TRASH);
+    lineFileAbort(lf, "%s not a recognized sequence (note: sequence names are case sensitive)",
+		  word);
 }
 
 void customFactorySetupDbTrack(struct customTrack *track)
 /* Fill in fields most database-resident custom tracks need. */
@@ -201,12 +165,11 @@
 
 static struct pipeline *bedLoaderPipe(struct customTrack *track)
 /* Set up pipeline that will load wig into database. */
 {
-char *db = customTrackTempDb();
 /* running the single command:
  *	hgLoadBed -customTrackLoader -tmpDir=/data/tmp
- *		-maxChromNameLength=${nameLength} db tableName stdin
+ *		-maxChromNameLength=${nameLength} customTrash tableName stdin
  * -customTrackLoader turns on options: -noNameIx -noHistory -ignoreEmpty
  *	-allowStartEqualEnd -allowNegativeScores -verbose=0
  */
 struct dyString *tmpDy = newDyString(0);
@@ -217,24 +180,21 @@
 int index = 2;
 
 if (stat(tmpDir,&statBuf))
     errAbort("can not find custom track tmp load directory: '%s'<BR>\n"
-	"create directory or specify in hg.conf customTrash.tmpdir", tmpDir);
+	"create directory or specify in hg.conf customTracks.tmpdir", tmpDir);
 dyStringPrintf(tmpDy, "-tmpDir=%s", tmpDir);
 cmd1[index++] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0);
 dyStringPrintf(tmpDy, "-maxChromNameLength=%d", track->maxChromName);
 cmd1[index++] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0);
 if(startsWithWord("bedGraph", track->dbTrackType))
     {
-    char buf[100];
     /* we currently assume that last field is the bedGraph field. */
-    safef(buf, sizeof(buf), "-bedGraph=%d", track->fieldCount);
-    cmd1[index++] = buf;
+    dyStringPrintf(tmpDy, "-bedGraph=%d", track->fieldCount);
+    cmd1[index++] = dyStringCannibalize(&tmpDy);
     }
-dyStringPrintf(tmpDy, "%s", db);
-cmd1[index++] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0);
-dyStringPrintf(tmpDy, "%s", track->dbTableName);
-cmd1[index++] = dyStringCannibalize(&tmpDy);
+cmd1[index++] = CUSTOM_TRASH;
+cmd1[index++] = track->dbTableName;
 cmd1[index++] = "stdin";
 assert(index <= ArraySize(cmd1));
 
 /* the "/dev/null" file isn't actually used for anything, but it is used
@@ -320,9 +280,8 @@
     if(ferror(out) || pipelineWait(dataPipe))
 	pipelineFailExit(track);	/* prints error and exits */
     unlink(track->dbStderrFile);	/* no errors, not used */
     pipelineFree(&dataPipe);
-    restorePrevEnv();			/* restore environment */
     }
 return track;
 }
 
@@ -586,13 +545,12 @@
 
 static struct pipeline *encodePeakLoaderPipe(struct customTrack *track)
 /* Set up pipeline that will load the encodePeak into database. */
 {
-char *db = customTrackTempDb();
 /* running the single command:
  *	hgLoadBed -customTrackLoader -sqlTable=loader/encodePeak.sql -renameSqlTable 
  *                -trimSqlTable -notItemRgb -tmpDir=/data/tmp
- *		-maxChromNameLength=${nameLength} db tableName stdin
+ *		-maxChromNameLength=${nameLength} customTrash tableName stdin
  */
 struct dyString *tmpDy = newDyString(0);
 char *cmd1[] = {"loader/hgLoadBed", "-customTrackLoader",
 	"-sqlTable=loader/encodePeak.sql", "-renameSqlTable", "-trimSqlTable", "-notItemRgb", NULL, NULL, NULL, NULL, NULL, NULL};
@@ -601,17 +559,15 @@
 int index = 6;
 
 if (stat(tmpDir,&statBuf))
     errAbort("can not find custom track tmp load directory: '%s'<BR>\n"
-	"create directory or specify in hg.conf customTrash.tmpdir", tmpDir);
+	"create directory or specify in hg.conf customTracks.tmpdir", tmpDir);
 dyStringPrintf(tmpDy, "-tmpDir=%s", tmpDir);
 cmd1[index++] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0);
 dyStringPrintf(tmpDy, "-maxChromNameLength=%d", track->maxChromName);
-cmd1[index++] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0);
-dyStringPrintf(tmpDy, "%s", db);
-cmd1[index++] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0);
-dyStringPrintf(tmpDy, "%s", track->dbTableName);
 cmd1[index++] = dyStringCannibalize(&tmpDy);
+cmd1[index++] = CUSTOM_TRASH;
+cmd1[index++] = track->dbTableName;
 cmd1[index++] = "stdin";
 assert(index <= ArraySize(cmd1));
 
 /* the "/dev/null" file isn't actually used for anything, but it is used
@@ -674,9 +630,8 @@
 if(ferror(out) || pipelineWait(dataPipe))
     pipelineFailExit(track);	/* prints error and exits */
 unlink(track->dbStderrFile);	/* no errors, not used */
 pipelineFree(&dataPipe);
-restorePrevEnv();			/* restore environment */
 return track;
 }
 
 static struct customTrack *encodePeakLoader(struct customFactory *fac,  
@@ -1121,9 +1076,8 @@
 /* build maf tab file and load in database */
 {
 customFactorySetupDbTrack(track);
 
-char *ctDb = customTrackTempDb();
 struct dyString *tmpDy = newDyString(0);
 char *cmd1[] = {"loader/hgLoadMaf", "-verbose=0", "-custom",  NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL};
 char **cmds[] = {cmd1, NULL};
@@ -1134,9 +1088,9 @@
 trashDirFile(&tn, "ct", "ct", ".pos");
 
 if (stat(tmpDir,&statBuf))
     errAbort("can not find custom track tmp load directory: '%s'<BR>\n"
-	"create directory or specify in hg.conf customTrash.tmpdir", tmpDir);
+	"create directory or specify in hg.conf customTracks.tmpdir", tmpDir);
 dyStringPrintf(tmpDy, "-tmpDir=%s", tmpDir);
 cmd1[3] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0);
 dyStringPrintf(tmpDy, "-loadFile=%s", mafFile);
 cmd1[4] = dyStringCannibalize(&tmpDy);  tmpDy = newDyString(0);
@@ -1145,9 +1099,9 @@
 dyStringPrintf(tmpDy, "-maxNameLen=%d", track->maxChromName);
 cmd1[6] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0); 
 dyStringPrintf(tmpDy, "-defPos=%s", tn.forCgi);
 cmd1[7] = dyStringCannibalize(&tmpDy);
-cmd1[8] = ctDb;
+cmd1[8] = CUSTOM_TRASH;
 cmd1[9] = track->dbTableName;
 
 struct pipeline *dataPipe =  pipelineOpen(cmds, 
     pipelineWrite | pipelineNoAbort, "/dev/null", track->dbStderrFile);
@@ -1155,9 +1109,8 @@
     pipelineFailExit(track);	/* prints error and exits */
 
 pipelineFree(&dataPipe);
 unlink(track->dbStderrFile);	/* no errors, not used */
-restorePrevEnv();			/* restore environment */
 track->wigFile = NULL;
 
 struct lineFile *lf = lineFileOpen(tn.forCgi, TRUE);
 char *line;
@@ -1267,9 +1220,8 @@
  *	loader/hgLoadWiggle -verbose=0 -noHistory -tmpDir=/data/tmp \
  *	    -maxChromNameLength=${nameLength} -chromInfoDb=${database} \
  *	    -pathPrefix=[.|/] ${db} ${table} stdin
  */
-char *db = customTrackTempDb();
 struct dyString *tmpDy = newDyString(0);
 char *cmd1[] = {"loader/wigEncode", "-verbose=0", "-wibSizeLimit=300000000", 
 	"stdin", "stdout", NULL, NULL};
 char *cmd2[] = {"loader/hgLoadWiggle", "-verbose=0", "-noHistory", NULL, NULL,
@@ -1281,23 +1233,23 @@
 cmd1[5] = track->wibFile;
 
 if (stat(tmpDir,&statBuf))
     errAbort("can not find custom track tmp load directory: '%s'<BR>\n"
-	"create directory or specify in hg.conf customTrash.tmpdir", tmpDir);
+	"create directory or specify in hg.conf customTracks.tmpdir", tmpDir);
 dyStringPrintf(tmpDy, "-tmpDir=%s", tmpDir);
 cmd2[3] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0);
 dyStringPrintf(tmpDy, "-maxChromNameLength=%d", track->maxChromName);
 cmd2[4] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0);
 dyStringPrintf(tmpDy, "-chromInfoDb=%s", track->genomeDb);
-cmd2[5] = dyStringCannibalize(&tmpDy); tmpDy = newDyString(0);
+cmd2[5] = dyStringCannibalize(&tmpDy);
 /* a system could be using /trash/ absolute reference, and nothing to do with
  *	local references, so don't confuse it with ./ a double // will work
  */
 if (startsWith("/", trashDir()))
     cmd2[6] = "-pathPrefix=/";
 else
     cmd2[6] = "-pathPrefix=.";
-cmd2[7] = db;
+cmd2[7] = CUSTOM_TRASH;
 cmd2[8] = track->dbTableName;
 /* the "/dev/null" file isn't actually used for anything, but it is used
  * in the pipeLineOpen to properly get a pipe started that isn't simply
  * to STDOUT which is what a NULL would do here instead of this name.
@@ -1371,9 +1323,8 @@
     if(ferror(out) || pipelineWait(dataPipe))
 	pipelineFailExit(track);	/* prints error and exits */
     unlink(track->dbStderrFile);	/* no errors, not used */
     pipelineFree(&dataPipe);
-    restorePrevEnv();			/* restore environment */
     track->wigFile = NULL;
 
     /* Figure out lower and upper limits with db query */
     struct sqlConnection *ctConn = hAllocConn(CUSTOM_TRASH);