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.h src/hg/hgSession/hgSession.h
index 692bac8..b455025 100644
--- src/hg/hgSession/hgSession.h
+++ src/hg/hgSession/hgSession.h
@@ -1,84 +1,89 @@
 /* hgSession - Manage information associated with a user identity. */
 
 /* Copyright (C) 2008 The Regents of the University of California 
  * See README in this or parent directory for licensing information. */
 
 #ifndef HGSESSION_H
 #define HGSESSION_H
 
 /* NOTE: some of the original contents have been moved up to cart.h for 
  * sharing with hgTracks. */
 
 #include "cart.h"
 
 /* Global variables - generally set during initialization and then read-only. */
 extern struct cart *cart;	/* This holds cgi and other variables between clicks. */
 extern char *database;		/* Current database, often but not always dbDatabase. */
 
 /* hgSession form inputs */
 #define hgsNewSessionName hgSessionPrefix "newSessionName"
 #define hgsNewSessionShare hgSessionPrefix "newSessionShare"
 #define hgsNewSessionDescription hgSessionPrefix "newSessionDescription"
 #define hgsDoNewSession hgSessionPrefix "doNewSession"
 
 #define hgsSharePrefix hgSessionPrefix "share_"
 #define hgsGalleryPrefix hgSessionPrefix "gallery_"
 #define hgsEditPrefix hgSessionPrefix "edit_"
 #define hgsLoadPrefix hgSessionPrefix "load_"
 #define hgsDeletePrefix hgSessionPrefix "delete_"
 
 #define hgsShowDownloadPrefix hgSessionPrefix "showDownload_"
 #define hgsMakeDownloadPrefix hgSessionPrefix "makeDownload_"
 #define hgsDoDownloadPrefix hgSessionPrefix "doDownload_"
 
 #define hgsSaveLocalBackupFileName hgSessionPrefix "saveLocalBackupFileName"
 #define hgsSaveLocalFileName hgSessionPrefix "saveLocalFileName"
 #define hgsSaveLocalFileCompress hgSessionPrefix "saveLocalFileCompress"
 #define hgsDoSaveLocal hgSessionPrefix "doSaveLocal"
 
 #define hgsLoadLocalFileName hgSessionPrefix "loadLocalFileName"
 #define hgsDoLoadLocal hgSessionPrefix "doLoadLocal"
 
 #define hgsLoadUrlName hgSessionPrefix "loadUrlName"
 #define hgsDoLoadUrl hgSessionPrefix "doLoadUrl"
 
 #define hgsDoMainPage hgSessionPrefix "doMainPage"
 
 #define hgsDoSessionDetail hgSessionPrefix "doSessionDetail"
 #define hgsOldSessionName hgSessionPrefix "oldSessionName"
 #define hgsDoSessionChange hgSessionPrefix "doSessionChange"
 
 #define hgsCancel hgSessionPrefix "cancel"
 
 #define hgsDo hgSessionPrefix "do"
 
 char *cgiDecodeClone(char *encStr);
 /* Allocate and return a CGI-decoded copy of encStr. */
 
 void startBackgroundWork(char *exec, char **pWorkUrl);
 /* deal with forking off child for background work
  * and setting up the trash file for communicating
  * from the child to the browser */
 
 void getBackgroundStatus(char *url);
 /* fetch status as the latest complete html block available.
  * fetch progress info instead if background proc still running. */
 
 // -----  htmlOpen 
 
 void htmlOpen(char *format, ...);
 /* Start up a page that will be in html format. */
 
 void htmlClose();
 /* Close down html format page. */
 
 void showDownloadSessionCtData(struct hashEl *downloadList);
 /* Show download page for the given session */
 
 void makeDownloadSessionCtData(char *param1, char *backgroundProgress);
 /* Download tables and data to save save in compressed archive. */
 
 void doDownloadSessionCtData(struct hashEl *downloadPathList);
 /* Download given table to browser to save. */
 
+void saveSessionData(struct cart *cart, char *encUserName, char *encSessionName);
+/* If hg.conf specifies safe places to store files and/or tables that belong to user sessions,
+ * then scan cart for trashDir files and/or customTrash tables, store them in safe locations,
+ * and update cart to point to the new locations. */
+
 #endif /* HGSESSION_H */