af07fb8909257db7da2b2d6258cca204f53a0daf
angie
  Fri Apr 17 12:53:17 2015 -0700
Libified hdb.c's trackDataAccessible for use in hgTrackDb, to add support for bigDataUrl-only tracks in -strict mode.
Also added a check for existence of file, if bigDataUrl is a file instead of a URL.
It would be good to further require in hgTrackDb that for bigDataUrl-based tracks,
tdb must also have a release tag in order to prevent /gbdb/ tracks from sneaking from
hgwbeta to RR -- but by the time pruneStrict is called, pruneRelease has already
removed the release tag!
More investigation required to see whether it's OK to call pruneStrict earlier.
refs #14379 #15059

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index ccee37b..2792ea2 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -29,30 +29,31 @@
 #include "liftOverChain.h"
 #include "grp.h"
 #include "twoBit.h"
 #include "ra.h"
 #include "genbank.h"
 #include "chromInfo.h"
 #ifndef GBROWSE
 #include "axtInfo.h"
 #include "ctgPos.h"
 #include "hubConnect.h"
 #include "customTrack.h"
 #include "hgFind.h"
 #endif /* GBROWSE */
 #include "hui.h"
 #include "trackHub.h"
+#include "net.h"
 #include "udc.h"
 #include "paraFetch.h"
 #include "filePath.h"
 
 
 #ifdef LOWELAB
 #define DEFAULT_PROTEINS "proteins060115"
 #define DEFAULT_GENOME "Pyrobaculum aerophilum"
 #else
 #define DEFAULT_PROTEINS "proteins"
 #define DEFAULT_GENOME "Human"
 #endif
 
 
 static struct sqlConnCache *hdbCc = NULL;  /* cache for primary database connection */
@@ -3575,35 +3576,51 @@
     if (loadOneTrackDb(db, where, one->name, &tdbList, loaded))
         foundOne = TRUE;
     }
 if (!foundOne)
     errAbort("can not find any trackDb tables for %s, check db.trackDb specification in hg.conf",
              db);
 slNameFreeList(&tableList);
 hashFree(&loaded);
 
 /* fill in supertrack fields, if any in settings */
 trackDbSuperMarkup(tdbList);
 trackDbAddTableField(tdbList);
 return tdbList;
 }
 
-static boolean trackDataAccessible(char *database, struct trackDb *tdb)
-/* Return TRUE if data accessible - meaning either it has a bigDataUrl, or the
- * table exists. */
+boolean trackDataAccessible(char *database, struct trackDb *tdb)
+/* Return TRUE if underlying data are accessible - meaning the track has either
+ * a bigDataUrl with remote URL (http:// etc), a bigDataUrl with an existing local file,
+ * or a database table with the same name.
+ * Note: this returns FALSE for composite tracks; use this on subtracks or simple tracks. */
 {
-return trackDbSetting(tdb, "bigDataUrl") != NULL || hTableForTrack(database, tdb->table) != NULL;
+char *bigDataUrl = trackDbSetting(tdb, "bigDataUrl");
+if (bigDataUrl != NULL)
+    {
+    if (hasProtocol(bigDataUrl))
+        return TRUE;
+    else
+        {
+        char *bigDataUrlLocal = hReplaceGbdb(bigDataUrl);
+        boolean exists = fileExists(bigDataUrlLocal);
+        freeMem(bigDataUrlLocal);
+        return exists;
+        }
+    }
+else
+    return (hTableForTrack(database, tdb->table) != NULL);
 }
 
 static void addTrackIfDataAccessible(char *database, struct trackDb *tdb,
 	       boolean privateHost, struct trackDb **tdbRetList)
 /* check if a trackDb entry should be included in display, and if so
  * add it to the list, otherwise free it */
 {
 if ((!tdb->private || privateHost) && trackDataAccessible(database, tdb))
     slAddHead(tdbRetList, tdb);
 else if (tdbIsDownloadsOnly(tdb))
     {
     // While it would be good to make table NULL, since we should support tracks
     // without tables (composties, etc) and even data tracks without tables (bigWigs).
     // However, some CGIs still need careful bullet-proofing.  I have done so with
     //   hgTrackUi, hgTracks, hgTable and hgGenome