9602d19ee87ad78e36ba6970cf4372937406d170
braney
  Thu Sep 7 15:57:32 2017 -0700
copy hgCollection hubs when saved or restored from sessions

diff --git src/hg/lib/trackHub.c src/hg/lib/trackHub.c
index 0287537..c2c708f 100644
--- src/hg/lib/trackHub.c
+++ src/hg/lib/trackHub.c
@@ -470,63 +470,68 @@
 
 return cloneString(buffer);
 }
 
 static int genomeOrderKeyCmp(const void *va, const void *vb)
 /* Compare to sort based on order key */
 {
 const struct trackHubGenome *a = *((struct trackHubGenome **)va);
 const struct trackHubGenome *b = *((struct trackHubGenome **)vb);
 
 if (b->orderKey > a->orderKey) return -1;
 else if (b->orderKey < a->orderKey) return 1;
 else return 0;
 }
 
-static struct trackHubGenome *trackHubGenomeReadRa(char *url, struct trackHub *hub)
+static struct trackHubGenome *trackHubGenomeReadRa(char *url, struct trackHub *hub, char *singleFile)
 /* Read in a genome.ra format url and return it as a list of trackHubGenomes. 
  * Also add it to hash, which is keyed by genome. */
 {
 struct lineFile *lf = udcWrapShortLineFile(url, NULL, 64*1024*1024);
 struct trackHubGenome *list = NULL, *el;
 struct hash *hash = hub->genomeHash;
 
 struct hash *ra;
 while ((ra = raNextRecord(lf)) != NULL)
     {
     // allow that trackDb+hub+genome is in one single file
     if (hashFindVal(ra, "hub"))
         continue;
     if (hashFindVal(ra, "track"))
         break;
 
     char *twoBitPath = hashFindVal(ra, "twoBitPath");
-    char *genome;
+    char *genome, *trackDb;
     if (twoBitPath != NULL)
 	genome = addHubName(hashFindVal(ra, "genome"), hub->name);
     else
 	genome = hashFindVal(ra, "genome");
     if (hub->defaultDb == NULL)
 	hub->defaultDb = genome;
     if (genome == NULL)
         badGenomeStanza(lf);
     if (hashLookup(hash, genome) != NULL)
         errAbort("Duplicate genome %s in stanza ending line %d of %s",
 		genome, lf->lineIx, lf->fileName);
-    char *trackDb = hashFindVal(ra, "trackDb");
+    if (singleFile == NULL)
+        {
+        trackDb = hashFindVal(ra, "trackDb");
         if (trackDb == NULL)
             badGenomeStanza(lf);
+        }
+    else
+        trackDb = singleFile;
     AllocVar(el);
     el->name = cloneString(genome);
     el->trackDbFile = trackHubRelativeUrl(url, trackDb);
     el->trackHub = hub;
     hashAdd(hash, el->name, el);
     slAddHead(&list, el);
     char *orderKey = hashFindVal(ra, "orderKey");
     if (orderKey != NULL)
 	el->orderKey = sqlUnsigned(orderKey);
 
     char *groups = hashFindVal(ra, "groups");
     if (twoBitPath != NULL)
 	{
 	el->description  = hashFindVal(ra, "description");
 	char *organism = hashFindVal(ra, "organism");
@@ -616,43 +621,57 @@
     errAbort("empty %s in trackHubOpen", url);
 // no errAbort when more records in hub.txt file: user can stuff
 // trackDb into it
 
 /* Allocate hub and fill in settings field and url. */
 AllocVar(hub);
 hub->url = cloneString(url);
 hub->name = cloneString(hubName);
 hub->settings = hubRa;
 
 /* Fill in required fields from settings. */
 trackHubRequiredSetting(hub, "hub");
 trackHubRequiredSetting(hub, "email");
 hub->shortLabel = trackHubRequiredSetting(hub, "shortLabel");
 hub->longLabel = trackHubRequiredSetting(hub, "longLabel");
+
+boolean isOneFile = (trackHubSetting(hub, "useOneFile") != NULL);
+char *ourFile = NULL;
+
+if (isOneFile)
+    {
+    ourFile = url;
+    char *root = strrchr(url, '/');
+    if (root)
+        ourFile = root + 1;
+    hub->genomesFile = cloneString(ourFile);
+    }
+else
     hub->genomesFile = trackHubRequiredSetting(hub, "genomesFile");
+
 hub->email =  trackHubSetting(hub, "email");
 hub->version = trackHubSetting(hub, "version"); // default to current version
 hub->level = trackHubSetting(hub, "level");     // "core" or "all"
 char *descriptionUrl = trackHubSetting(hub, "descriptionUrl");
 if (descriptionUrl != NULL)
     hub->descriptionUrl = trackHubRelativeUrl(hub->url, descriptionUrl);
 
 lineFileClose(&lf);
 char *genomesUrl = trackHubRelativeUrl(hub->url, hub->genomesFile);
 
 hub->genomeHash = hashNew(8);
-hub->genomeList = trackHubGenomeReadRa(genomesUrl, hub);
+hub->genomeList = trackHubGenomeReadRa(genomesUrl, hub, ourFile);
 freez(&genomesUrl);
 
 cacheHub(hub);
 return hub;
 }
 
 void trackHubClose(struct trackHub **pHub)
 /* Close up and free resources from hub. */
 {
 struct trackHub *hub = *pHub;
 if (hub != NULL)
     {
     trackHubGenomeFreeList(hub);
     freeMem(hub->url);
     hashFree(&hub->settings);