02af9dedd3443875fc2b3eee09c48a5e6f85b1c3 chmalee Wed Nov 6 15:27:22 2024 -0800 Start of work on optional subdir and hubName metadata for hubtools uploads diff --git src/hg/lib/userdata.c src/hg/lib/userdata.c index dea277b..cb333bd 100644 --- src/hg/lib/userdata.c +++ src/hg/lib/userdata.c @@ -118,49 +118,62 @@ FILE *f = mustOpen(hubFile, "w"); //fprintf(stderr, "would write \"hub %s\nemail %s\nshortLabel %s\nlongLabel %s\nuseOneFile on\n\ngenome %s\n\n\" to %s", hubName, emailForUserName(userName), hubName, hubName, db, hubFile); fprintf(f, "hub %s\n" "email %s\n" "shortLabel %s\n" "longLabel %s\n" "useOneFile on\n" "\n" "genome %s\n" "\n", encodedHubName, emailForUserName(userName), hubName, hubName, db); carefulClose(&f); return hubFile; } -char *createNewTempHubForUpload(char *requestId, char *userName, char *db, char *trackFileName, char *trackType) +char *createNewTempHubForUpload(char *requestId, char *userName, char *db, char *trackFileName, char *trackType, char *reqHubName) /* Creates a hub.txt for this upload with a random hub name. Returns the full path to the hub - * for convenience. */ + * for convenience. If the reqHubName argument is non-NULL, use that as the hub name instead of + * a random string AND do not create a hub.txt, only for use from hubtools up command */ { -char *encodedHubName = cgiEncodeFull(requestId); -char *path = prefixUserFile(userName, encodedHubName); -char *hubFileName = writeHubText(path, userName, encodedHubName, requestId, db); +char *encodedHubName = reqHubName != NULL ? cgiEncodeFull(reqHubName) : cgiEncodeFull(requestId); +char *hubFileName = NULL; +char *path = NULL; +if (reqHubName) + { + // coming from hubtools command + struct dyString *hubPath = dyStringNew(0); + dyStringPrintf(hubPath, "%s%s/hub.txt", getDataDir(userName), reqHubName); + path = hubFileName = dyStringCannibalize(&hubPath); + } +else + { + path = prefixUserFile(userName, encodedHubName); + hubFileName = writeHubText(path, userName, encodedHubName, requestId, db); char *encodedTrack = cgiEncodeFull(trackFileName); struct dyString *trackFilePath = dyStringCreate("../%s", encodedTrack); FILE *f = mustOpen(hubFileName, "a"); fprintf(f, "track %s\n" "bigDataUrl %s\n" "type %s\n" "shortLabel %s\n" "longLabel %s\n" "\n", encodedTrack, dyStringCannibalize(&trackFilePath), trackType, trackFileName, trackFileName); carefulClose(&f); + } // we should update the mysql table now with a record of the hub.txt struct hubSpace *row = NULL; AllocVar(row); row->userName = userName; row->fileName = hubFileName; row->fileSize = fileSize(hubFileName); row->fileType = "hub"; row->creationTime = NULL; time_t lastModTime = fileModTime(hubFileName); row->lastModified = sqlUnixTimeToDate(&lastModTime, TRUE); row->hubNameList = ""; row->db = db; row->location = path; row->md5sum = md5HexForFile(hubFileName);