23b10b9fed9b850a60b7f601c6275811caa812e6
angie
  Mon Dec 3 11:43:50 2018 -0800
Don't reuse trash files where it can be avoided -- make new cart files when there are changes, so that we don't have to copy files every time we save or load a session.  refs #22440

diff --git src/hg/lib/cart.c src/hg/lib/cart.c
index 36dc637..c3c6675 100644
--- src/hg/lib/cart.c
+++ src/hg/lib/cart.c
@@ -291,31 +291,30 @@
 {
 struct dyString *dy = dyStringNew(1024);
 int useCount;
 sqlDyStringPrintf(dy, "SELECT useCount FROM %s "
 	       "WHERE userName = '%s' AND sessionName = '%s';",
 	       namedSessionTable, encUserName, encSessionName);
 useCount = sqlQuickNum(conn, dy->string) + 1;
 dyStringClear(dy);
 sqlDyStringPrintf(dy, "UPDATE %s SET useCount = %d, lastUse=now() "
 	       "WHERE userName = '%s' AND sessionName = '%s';",
 	       namedSessionTable, useCount, encUserName, encSessionName);
 sqlUpdate(conn, dy->string);
 dyStringFree(&dy);
 }
 
-#ifndef GBROWSE
 static void copyCustomComposites(struct cart *cart, struct hashEl *el)
 /* Copy a set of custom composites to a new hub file. Update the 
  * relevant cart variables. */
 {
 struct tempName hubTn;
 char *hubFileVar = cloneString(el->name);
 char *db = el->name + sizeof(CUSTOM_COMPOSITE_SETTING);
 char *oldHubFileName = el->val;
 trashDirDateFile(&hubTn, "hgComposite", "hub", ".txt");
 char *newHubFileName = cloneString(hubTn.forCgi);
 
 // let's make sure the hub hasn't been cleaned up
 int fd = open(oldHubFileName, O_RDONLY);
 if (fd < 0)
     {
@@ -365,71 +364,30 @@
 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(CT_FILE_VAR_PREFIX, el->name))
-	{
-	char *db = &el->name[strlen(CT_FILE_VAR_PREFIX)];
-	struct slName *browserLines = NULL;
-	struct customTrack *ctList = NULL;
-	char *ctFileName = (char *)(el->val);
-	if (fileExists(ctFileName))
-	    ctList = customFactoryParseAnyDb(db, ctFileName, TRUE, &browserLines, FALSE);
-        /* Save off only if the custom tracks are live -- if none are live,
-         * leave cart variables in place so hgSession can detect and inform
-         * the user. */
-	if (ctList)
-	    {
-	    struct customTrack *ct;
-	    static struct tempName tn;
-	    char *ctFileVar = el->name;
-	    char *ctFileName;
-	    for (ct = ctList;  ct != NULL;  ct = ct->next)
-		{
-		copyFileToTrash(&(ct->htmlFile), "ct", CT_PREFIX, ".html");
-		copyFileToTrash(&(ct->wibFile), "ct", CT_PREFIX, ".wib");
-		copyFileToTrash(&(ct->wigFile), "ct", CT_PREFIX, ".wig");
-		}
-	    trashDirFile(&tn, "ct", CT_PREFIX, ".bed");
-	    ctFileName = tn.forCgi;
-	    cartSetString(cart, ctFileVar, ctFileName);
-	    customTracksSaveFile(db, ctList, ctFileName);
-	    }
-	}
-    }
-}
-#endif /* GBROWSE */
-
 static void storeInOldVars(struct cart *cart, struct hash *oldVars, char *var)
 /* Store all cart hash elements for var into oldVars (if it exists). */
 {
 if (oldVars == NULL)
     return;
 struct hashEl *hel = hashLookup(cart->hash, var);
 
 // NOTE: New cgi vars not in old cart cannot be distinguished from vars not newly set by cgi.
 //       Solution: Add 'empty' var to old vars for cgi vars not already in cart
 if (hel == NULL)
     hashAdd(oldVars, var, cloneString(CART_VAR_EMPTY));
 
 while (hel != NULL)
     {
     hashAdd(oldVars, var, cloneString(hel->val));
@@ -1390,35 +1348,30 @@
     }
 #endif /* GBROWSE */
 
 /* wire up the assembly hubs so we can operate without sql */
 setUdcTimeout(cart);
 if (cartVarExists(cart, hgHubDoDisconnect))
     doDisconnectHub(cart);
 
 if (didSessionLoad)
     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");
             }