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/lib/cart.c src/hg/lib/cart.c index c3c6675..371aac3 100644 --- src/hg/lib/cart.c +++ src/hg/lib/cart.c @@ -296,94 +296,103 @@ 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); } 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 *hubFileVar = el->name; 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) { - cartRemove(cart, el->name); + cartRemove(cart, hubFileVar); return; } close(fd); copyFile(oldHubFileName, newHubFileName); +cartReplaceHubVars(cart, hubFileVar, oldHubFileName, newHubFileName); +} +void cartReplaceHubVars(struct cart *cart, char *hubFileVar, char *oldHubUrl, char *newHubUrl) +/* Replace all cart variables corresponding to oldHubUrl (and/or its hub ID) with + * equivalents for newHubUrl. */ +{ +if (! startsWith(customCompositeCartName, hubFileVar)) + errAbort("cartReplaceHubVars: expected hubFileVar to begin with '"customCompositeCartName"' " + "but got '%s'", hubFileVar); +char *db = hubFileVar + strlen(customCompositeCartName "-"); char *errorMessage; -unsigned oldHubId = hubFindOrAddUrlInStatusTable(db, cart, oldHubFileName, &errorMessage); -unsigned newHubId = hubFindOrAddUrlInStatusTable(db, cart, newHubFileName, &errorMessage); +unsigned oldHubId = hubFindOrAddUrlInStatusTable(db, cart, oldHubUrl, &errorMessage); +unsigned newHubId = hubFindOrAddUrlInStatusTable(db, cart, newHubUrl, &errorMessage); // need to change hgHubConnect.hub.#hubNumber# (connected hubs) struct slPair *hv, *hubVarList = cartVarsWithPrefix(cart, hgHubConnectHubVarPrefix); char buffer[4096]; for(hv = hubVarList; hv; hv = hv->next) { unsigned hubId = sqlUnsigned(hv->name + strlen(hgHubConnectHubVarPrefix)); if (hubId == oldHubId) { cartRemove(cart, hv->name); safef(buffer, sizeof buffer, "%s%d", hgHubConnectHubVarPrefix, newHubId); cartSetString(cart, buffer, "1"); } } // need to change hub_#hubNumber#* (track visibilities) safef(buffer, sizeof buffer, "%s%d_", hubTrackPrefix, oldHubId); int oldNameLength = strlen(buffer); hubVarList = cartVarsWithPrefix(cart, buffer); for(hv = hubVarList; hv; hv = hv->next) { 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 expOrder_hub_#hubNumber#, simOrder_hub_#hubNumber# (sorting) -- values too // need to change trackHubs #hubNumber# cartSetString(cart, hgHubConnectRemakeTrackHub, "on"); -cartSetString(cart, hubFileVar, newHubFileName); +cartSetString(cart, hubFileVar, newHubUrl); } 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)) + if (startsWith(customCompositeCartName, el->name)) copyCustomComposites(cart, el); } } 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));