e6cd762cc1e6ba7103394e13f2612198106881fc
braney
  Sat Nov 18 14:16:48 2017 -0800
copy custom composites before hub load, but copy custom tracks AFTER hub
load.

diff --git src/hg/lib/cart.c src/hg/lib/cart.c
index 0d2a628..d101b60 100644
--- src/hg/lib/cart.c
+++ src/hg/lib/cart.c
@@ -351,30 +351,42 @@
     {
     char *name = hv->name + oldNameLength;
     safef(buffer, sizeof buffer, "%s%d_%s", hubTrackPrefix, newHubId, name);
     cartSetString(cart, buffer, cloneString(hv->val));
     cartRemove(cart, hv->name);
     }
 
 // need to change hgtgroup_hub_#hubNumber# (blue bar open )
 // need to change expOrder_hub_#hubNumber#, simOrder_hub_#hubNumber# (sorting)
 
 // need to change trackHubs #hubNumber#   
 cartSetString(cart, hgHubConnectRemakeTrackHub, "on");
 cartSetString(cart, hubFileVar, newHubFileName);
 }
 
+void cartCopyCustomComposites(struct cart *cart)
+/* Find any custom composite hubs and copy them so they can be modified. */
+{
+struct hashEl *el, *elList = hashElListHash(cart->hash);
+
+for (el = elList; el != NULL; el = el->next)
+    {
+    if (startsWith(CUSTOM_COMPOSITE_SETTING, el->name))
+        copyCustomComposites(cart, el);
+    }
+}
+
 void cartCopyCustomTracks(struct cart *cart)
 /* If cart contains any live custom tracks, save off a new copy of them,
  * to prevent clashes by multiple uses of the same session.  */
 {
 struct hashEl *el, *elList = hashElListHash(cart->hash);
 
 for (el = elList; el != NULL; el = el->next)
     {
     if (startsWith(CUSTOM_COMPOSITE_SETTING, el->name))
         copyCustomComposites(cart, el);
     if (startsWith(CT_FILE_VAR_PREFIX, el->name))
 	{
 	char *db = &el->name[strlen(CT_FILE_VAR_PREFIX)];
 	struct slName *browserLines = NULL;
 	struct customTrack *ctList = NULL;
@@ -828,39 +840,42 @@
 	char *url = cartString(cart, hgsLoadUrlName);
 	struct lineFile *lf = netLineFileOpen(url);
 	cartLoadSettings(lf, cart, oldVars, hgsDoLoadUrl);
 	lineFileClose(&lf);
 	cartTrace(cart, "after cartLS", conn);
 	didSessionLoad = TRUE;
 	}
     }
 #endif /* GBROWSE */
 
 /* wire up the assembly hubs so we can operate without sql */
 setUdcTimeout(cart);
 if (cartVarExists(cart, hgHubDoDisconnect))
     doDisconnectHub(cart);
 
-#ifndef GBROWSE
 if (didSessionLoad)
-    cartCopyCustomTracks(cart);
-#endif /* GBROWSE */
+    cartCopyCustomComposites(cart);
 
 pushWarnHandler(cartHubWarn);
 char *newDatabase = hubConnectLoadHubs(cart);
 popWarnHandler();
 
+#ifndef GBROWSE
+if (didSessionLoad)
+    cartCopyCustomTracks(cart);
+#endif /* GBROWSE */
+
 if (newDatabase != NULL)
     {
     char *cartDb = cartOptionalString(cart, "db");
 
     if ((cartDb == NULL) || differentString(cartDb, newDatabase))
         {
         // this is some magic to use the defaultPosition and reset cart variables
         if (oldVars)
             {
             struct hashEl *hel;
             if ((hel = hashLookup(oldVars,"db")) != NULL)
                 hel->val = "none";
             else
                 hashAdd(oldVars, "db", "none");
             }