a8273be9da3b7a87a8d829d3efb79bce66e22039
angie
  Wed Jan 23 17:42:02 2019 -0800
New hg.conf settings sessionDataDir and sessionDataDbPrefix enable hgSession to move saved session trash files and customTrash tables into safe storage, so trash cleaner can be simpler.  refs #22440

When hgSession saves a session to namedSessionDb:
* If sessionDataDir is set in hg.conf (e.g. /data/apache/userdata on hgwdev), trash paths in cart variable values and in the contents of ctfile_$db and customComposite-$db files are replaced with paths in a directory hierarchy under sessionDataDir.  Files are moved from trash into the new directories and symlinks are made from trash locations to new locations.
* If sessionDataDbPrefix is set in hg.conf (e.g. customData), customTrash tables named in dbTableName settings in ctfile_$db are moved to a <sessionDataDbPrefix><dayOfMonth> database (e.g. customData03 on the third day of the month).  dbTableName settings are updated to point to the new locations.  If sessionDataDir is also set and a table contains a trash path, then the table is updated to contain to the new path under sessionDataDir.

sessionDataDir must be an absolute path to keep the symlinks straightforward.

The new directory hierarchy under sessionDataDir is A/B/C/D where A-D are defined as follows:
* A: the first two characters of the hex string md5sum of namedSessionDb.userName, i.e. the URI-encoded username truncated to varchar(32)
(there can be tens of thousands of userNames; using this mini-hash distributes them across up to 256 subdirectories of sessionDataDir)
* B: the URI-encoded userName
* C: the first 8 characters of the hex string md5sum of namedSessionDb.sessionName, i.e. the URI-encoded session name truncated to varchar(255)
* D: the original path below ../trash/

So, for example, the file ../trash/ct/ct_hgwdev_angie_11fc0_2b5970.maf could be moved to
/data/apache/userdata/fb/AngieHinrichs/cf2a2304/ct/ct_hgwdev_angie_11fc0_2b5970.maf

diff --git src/hg/hgSession/hgSession.c src/hg/hgSession/hgSession.c
index 59f5ac6..c6deead 100644
--- src/hg/hgSession/hgSession.c
+++ src/hg/hgSession/hgSession.c
@@ -25,31 +25,30 @@
 #include "jsHelper.h"
 #include "web.h"
 #include "hdb.h"
 #include "ra.h"
 #include "wikiLink.h"
 #include "customTrack.h"
 #include "customFactory.h"
 #include "udc.h"
 #include "hgSession.h"
 #include "hgConfig.h"
 #include "sessionThumbnail.h"
 #include "filePath.h"
 #include "obscure.h"
 #include "trashDir.h"
 #include "hubConnect.h"
-
 #include "trackHub.h"
 
 void usage()
 /* Explain usage and exit. */
 {
 errAbort(
   "hgSession - Interface with wiki login and do session saving/loading.\n"
   "usage:\n"
   "    hgSession <various CGI settings>\n"
   );
 }
 
 /* Global variables. */
 struct cart *cart;
 char *excludeVars[] = {"Submit", "submit", NULL};
@@ -788,30 +787,32 @@
     if ((row = sqlNextRow(sr)) != NULL)
 	{
 	safef(firstUseBuf, sizeof(firstUseBuf), "'%s'", row[0]);
 	firstUse = firstUseBuf;
 	useCount = atoi(row[1]) + 1;
 	}
     sqlFreeResult(&sr);
 
     /* Remove pre-existing session (if any) before updating. */
     dyStringClear(dy);
     sqlDyStringPrintf(dy, "DELETE FROM %s WHERE userName = '%s' AND "
 		       "sessionName = '%s';",
 		   namedSessionTable, encUserName, encSessionName);
     sqlUpdate(conn, dy->string);
 
+    saveSessionData(cart, encUserName, encSessionName);
+
     dyStringClear(dy);
     sqlDyStringPrintf(dy, "INSERT INTO %s ", namedSessionTable);
     dyStringAppend(dy, "(userName, sessionName, contents, shared, "
 		       "firstUse, lastUse, useCount, settings) VALUES (");
     dyStringPrintf(dy, "'%s', '%s', ", encUserName, encSessionName);
     dyStringAppend(dy, "'");
     cleanHgSessionFromCart(cart);
     struct dyString *encoded = newDyString(4096);
     cartEncodeState(cart, encoded);
 
     // Now add all the default visibilities to output.
     outDefaultTracks(cart, encoded);
 
     sqlDyAppendEscaped(dy, encoded->string);
     dyStringFree(&encoded);