90a4b891ec9646bb4f4448a2bf53e714a8aa4492 chmalee Fri Jan 17 11:55:54 2025 -0800 When creating track stanzas after uploading a file to hubspace, wrap the bigBedFileOpen call in an errCatch so that if the file is actually not a bigBed, the user doesn't encounter some mysterious behavior when bigBedFileOpen errAborts, refs #35064 diff --git src/hg/lib/userdata.c src/hg/lib/userdata.c index d62bd66..0bfbdf8 100644 --- src/hg/lib/userdata.c +++ src/hg/lib/userdata.c @@ -7,30 +7,31 @@ #include "common.h" #include "hash.h" #include "portable.h" #include "trashDir.h" #include "md5.h" #include "hgConfig.h" #include "dystring.h" #include "cheapcgi.h" #include "customFactory.h" #include "wikiLink.h" #include "userdata.h" #include "jksql.h" #include "hdb.h" #include "hubSpace.h" #include "hubSpaceQuotas.h" +#include "errCatch.h" #include <limits.h> char *getUserName() /* Query the right system for the users name */ { return (loginSystemEnabled() || wikiLinkEnabled()) ? wikiLinkUserName() : NULL; } char *emailForUserName(char *userName) /* Fetch the email for this user from gbMembers hgcentral table */ { struct sqlConnection *sc = hConnectCentral(); struct dyString *query = sqlDyStringCreate("select email from gbMembers where userName = '%s'", userName); char *email = sqlQuickString(sc, dyStringCannibalize(&query)); hDisconnectCentral(&sc); @@ -257,37 +258,47 @@ char *firstSlash = strchr(copy, '/'); if (!firstSlash) { return copy; } firstSlash = 0; return catTwoStrings(userDataDir, copy); } static void writeTrackStanza(char *hubFileName, char *track, char *bigDataUrl, char *type, char *label, char *bigFileLocation) { FILE *f = mustOpen(hubFileName, "a"); char *trackDbType = type; if (sameString(type, "bigBed")) { + // don't errAbort if the file is actually not a bigBed + struct errCatch *errCatch = errCatchNew(); + if (errCatchStart(errCatch)) + { // figure out the type based on the bbiFile header struct bbiFile *bbi = bigBedFileOpen(bigFileLocation); char tdbType[32]; safef(tdbType, sizeof(tdbType), "bigBed %d%s", bbi->definedFieldCount, bbi->fieldCount > bbi->definedFieldCount ? " +" : ""); trackDbType = tdbType; bigBedFileClose(&bbi); } + errCatchEnd(errCatch); + errCatchFree(&errCatch); + // NOTE: if the file was not actually a bigBed (and so bigBedFileOpen errAborted), we + // just want to prevent the errAbort, not prevent creating the stanza itself, as that + // would be majorly confusing to the user, so just continue on here + } fprintf(f, "track %s\n" "bigDataUrl %s\n" "type %s\n" "shortLabel %s\n" "longLabel %s\n" "\n", track, bigDataUrl, trackDbType, label, label); carefulClose(&f); } static char *writeHubStanzasForFile(struct hubSpace *rowForFile, char *userDataDir, char *parentDir) /* Create a hub.txt (if necessary) and add track stanzas for the file described by rowForFile. * Returns the path to the hub.txt */ { char *hubFileName = NULL;