b0828e726eba3cbd345f94f1ed0ad1b334424f7d
angie
  Thu Mar 14 10:38:31 2013 -0700
Fixing bug reported via MLQ: When repeatedly adding/modifying customtracks and saving sessions without any cartResets or session loads,
the same ctfile was used in both saved sessions and the user's active
cart, so modifications after saving a session were leaking back to
saved sessions.  Fix: copy custom tracks not only when loading a
saved session, but also immediately after saving a session, so that
the user's active cart no longer has the same ctfile (and customTrash
database tables, etc) as the saved session.
fixes #10396, refs #10323

diff --git src/hg/hgSession/hgSession.c src/hg/hgSession/hgSession.c
index 23e2439..875b7c4 100644
--- src/hg/hgSession/hgSession.c
+++ src/hg/hgSession/hgSession.c
@@ -638,30 +638,33 @@
 
     dyStringClear(dy);
     dyStringPrintf(dy, "INSERT INTO %s ", namedSessionTable);
     dyStringAppend(dy, "(userName, sessionName, contents, shared, "
 		       "firstUse, lastUse, useCount) VALUES (");
     dyStringPrintf(dy, "'%s', '%s', ", encUserName, encSessionName);
     dyStringAppend(dy, "'");
     cleanHgSessionFromCart(cart);
     cartEncodeState(cart, dy);
     dyStringAppend(dy, "', ");
     dyStringPrintf(dy, "%d, ", (shareSession ? 1 : 0));
     dyStringPrintf(dy, "%s, now(), %d);", firstUse, useCount);
     sqlUpdate(conn, dy->string);
     dyStringFree(&dy);
 
+    /* Prevent modification of custom tracks just saved to namedSessionDb: */
+    cartCopyCustomTracks(cart, cartUsualString(cart, "db", hDefaultDb()));
+
     if (useCount > INITIAL_USE_COUNT)
 	dyStringPrintf(dyMessage,
 	  "Overwrote the contents of session <B>%s</B> "
 	  "(that %s be shared with other users).  "
 	  "%s %s",
 	  htmlEncode(sessionName), (shareSession ? "may" : "may not"),
 	  getSessionLink(encUserName, encSessionName),
 	  getSessionEmailLink(encUserName, encSessionName));
     else
 	dyStringPrintf(dyMessage,
 	  "Added a new session <B>%s</B> that %s be shared with other users.  "
 	  "%s %s",
 	  htmlEncode(sessionName), (shareSession ? "may" : "may not"),
 	  getSessionLink(encUserName, encSessionName),
 	  getSessionEmailLink(encUserName, encSessionName));