b318572799b35ed9cd6fabdeb247495d72d4da4c chmalee Tue Jun 3 18:07:28 2025 -0700 Make the serverName a required input to hubspace uploads so the hubspace machine can determine where to place uploads. Prevents any current or future username collisions between euro and rr and prevents tusd temp file collisions between the machines, refs #31058 diff --git src/hg/hgHubConnect/hooks/pre-create.c src/hg/hgHubConnect/hooks/pre-create.c index ebb80d1dd83..c38c6d1caa5 100644 --- src/hg/hgHubConnect/hooks/pre-create.c +++ src/hg/hgHubConnect/hooks/pre-create.c @@ -5,30 +5,31 @@ * of success, return a JSON encoded response back to the * client. */ #include "common.h" #include "linefile.h" #include "hash.h" #include "options.h" #include "wikiLink.h" #include "customTrack.h" #include "userdata.h" #include "jsonQuery.h" #include "jsHelper.h" #include "errCatch.h" #include "obscure.h" #include "hooklib.h" #include "hubSpaceKeys.h" +#include "htmshell.h" void usage() /* Explain usage and exit. */ { errAbort( "pre-create - tus daemon pre-create hook program\n" "usage:\n" " pre-create < input\n" ); } /* Command line validation table. */ static struct optionSpec options[] = { {NULL, 0}, }; @@ -68,52 +69,78 @@ setenv("HTTP_COOKIE", reqCookie, 0); } fprintf(stderr, "reqCookie='%s'\n", reqCookie); char *userName = getUserName(); if (!userName) { // maybe an apiKey was provided, use that instead to look up the userName char *apiKey = jsonQueryString(req, "", "Event.Upload.MetaData.apiKey", NULL); userName = userNameForApiKey(apiKey); if (!userName) errAbort("You are not logged in. Please navigate to My Data -> My Sessions and log in or create an account."); } fprintf(stderr, "userName='%s'\n'", userName); long reqFileSize = jsonQueryInt(req, "", "Event.Upload.Size", 0, NULL); char *reqFileName = jsonQueryString(req, "", "Event.Upload.MetaData.fileName", NULL); + char *reqServerName = jsonQueryString(req, "", "Event.Upload.MetaData.serverName", NULL); + char *reqParentDir = jsonQueryString(req, "", "Event.Upload.MetaData.parentDir", NULL); + boolean isHubToolsUpload = FALSE; + char *hubtoolsStr = jsonQueryString(req, "", "Event.Upload.MetaData.hubtools", NULL); + if (hubtoolsStr) + isHubToolsUpload = sameString(hubtoolsStr, "TRUE") || sameString(hubtoolsStr, "true"); long currQuota = checkUserQuota(userName); long newQuota = currQuota + reqFileSize; long maxQuota = getMaxUserQuota(userName); if (newQuota > maxQuota) { errAbort("File '%s' is too large, need %s free space but current used space is %s out of %s", reqFileName, prettyFileSize(reqFileSize), prettyFileSize(currQuota), prettyFileSize(maxQuota)); } char *reqFileType = jsonQueryString(req, "", "Event.Upload.MetaData.fileType", NULL); if (!isFileTypeRecognized(reqFileType)) { errAbort("File type '%s' for file '%s' is not accepted at this time", reqFileType, reqFileName); } char *reqGenome = jsonQueryString(req, "", "Event.Upload.MetaData.genome", NULL); if (!reqGenome) { errAbort("Genome selection is NULL for file '%s' is invalid. Please choose the correct genome", reqFileName); } // we've passed all the checks so we can return that we are good to upload the file if (exitStatus == 0) + { + // set the location of the upload to the location it will ultimately live, which + // depends on the machine name (euro, rr, beta, etc) and the user name + char *location = setUploadPath(userName, reqFileName, reqParentDir, reqServerName, isHubToolsUpload); + if (!location) + { + errAbort("Error setting upload path in pre-create for file '%s'. This is an" + " issue with our server, please email genome-www@soe.ucsc.edu with your" + " userName so we can investigate.", reqFileName); + } + struct hash *changeObjHash = hashNew(0); + struct hash *pathObjHash = hashNew(0); + struct jsonElement *changeObj = newJsonObject(changeObjHash); + struct jsonElement *pathObj = newJsonObject(pathObjHash); + + jsonObjectAdd(pathObj, "Path", newJsonString(location)); + jsonObjectAdd(changeObj, "Storage", pathObj); + jsonObjectAdd(changeObj, "ID", newJsonString(makeRandomKey(128))); + jsonObjectAdd(response, "ChangeFileInfo", changeObj); fillOutHttpResponseSuccess(response); } + } if (errCatch->gotError) { rejectUpload(response, errCatch->message->string); exitStatus = 1; } errCatchEnd(errCatch); } // always print a response no matter what jsonPrintToFile(response, NULL, stdout, 0); return 0; } int main(int argc, char *argv[]) /* Process command line. */ {