deac2d6a8dfdae141830f4ac0b79d86c48d0f0a0
max
  Wed Mar 12 07:23:25 2014 -0700
Moving code from commit 0fb6cafc5cebeb0f383804ed9df2cd01be10227f into hdbbecause it's also needed by hgPcr. refs #11957. (Should not affect RR, as
hReplaceGbdb will return the same string, so it only adds and then
removes a .2bit filename from the path.)

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index 5e97336..ae50298 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -1289,30 +1289,51 @@
 
 path = replaceChars(fileName, "/gbdb/", newGbdbLoc);
 if (fileExists(path))
     return path;
 
 // if the file did not exist, replace with gbdbLoc2
 newGbdbLoc = cfgOption("gbdbLoc2");
 if (newGbdbLoc==NULL)
     return path;
 
 freeMem(path);
 path = replaceChars(fileName, "/gbdb/", newGbdbLoc);
 return path;
 }
 
+char *hReplaceGbdbSeqDir(char *path, char *db)
+/* similar to hReplaceGbdb, but accepts a nib or 2bit "directory" (basename) under
+ * gbdb, like /gbdb/hg19 (which by jkLib is translated to /gbdb/hg19/hg19.2bit).
+ hReplaceGbdb would check only if the dir exists. For 2bit basename, we
+ have to check if the 2bit file exists, do the rewriting, then strip off the
+ 2bit filename again. Otherwise, /gbdb/hg19 will never be rewritten, as it
+ exists but might be empty and without a 2bit file.
+ This function works with .nib directories, but nib does not support opening
+ from URLs.  As of Feb 2014, only hg16 and anoGam1 use a .nib directory.
+*/
+{
+char buf[4096];
+safef(buf, sizeof(buf), "%s/%s.2bit", path, db);
+char *newPath = hReplaceGbdb(buf);
+
+char dir[4096];
+splitPath(newPath, dir, NULL, NULL);
+freeMem(newPath);
+return cloneString(dir);
+}
+
 char *hTryExtFileNameC(struct sqlConnection *conn, char *extFileTable, unsigned extFileId, boolean abortOnError)
 /* Get external file name from table and ID.  Typically
  * extFile table will be 'extFile' or 'gbExtFile'
  * If abortOnError is true, abort if the id is not in the table or if the file
  * fails size check, otherwise return NULL if either of those checks fail.   
  * Please freeMem the result when you are done with it. 
  * (requires conn passed in) 
  */
 {
 char query[256];
 struct sqlResult *sr;
 char **row;
 long long dbSize, diskSize;
 char *path;