a4ec09b5bbfbaf7c4f40053b24f42f075a5b6b85
chmalee
  Tue Nov 12 14:23:32 2024 -0800
Lots of changes after meeting, mostly to accomadate hubtools uploads: allow parentDir in upload request, make batch change dropdowns have the right options. TODO: remove type selection all together from UI, make hub name generation not be hardcoded in ui

diff --git src/hg/hgHubConnect/hooks/post-finish.c src/hg/hgHubConnect/hooks/post-finish.c
index a2d460b..98b6332 100644
--- src/hg/hgHubConnect/hooks/post-finish.c
+++ src/hg/hgHubConnect/hooks/post-finish.c
@@ -54,78 +54,81 @@
     }
 else
     {
     struct errCatch *errCatch = errCatchNew(0);
     if (errCatchStart(errCatch))
         {
         // the variables for the row entry for this file, some can be NULL
         char *userName = NULL;
         char *fileName = NULL;
         long long fileSize = 0;
         char *fileType = NULL;
         char *db = NULL;
         char *location = NULL;
         char *reqLm = NULL;
         time_t lastModified = 0;
-        char *parentDir = NULL; // special optional argument from hubtools commands
-        char *reqHubName = NULL; // special optional argument from hubtools commands
+        char *parentDir = NULL;
 
         struct lineFile *lf = lineFileStdin(FALSE);
         char *request = lineFileReadAll(lf);
         struct jsonElement *req = jsonParse(request);
         fprintf(stderr, "Hook request:\n");
         jsonPrintToFile(req, NULL, stderr, 0);
         char *reqCookie= jsonQueryString(req, "", "Event.HTTPRequest.Header.Cookie[0]", NULL);
         if (reqCookie)
             {
             setenv("HTTP_COOKIE", reqCookie, 0);
             }
         fprintf(stderr, "reqCookie='%s'\n", reqCookie);
         userName = (loginSystemEnabled() || wikiLinkEnabled()) ? wikiLinkUserName() : NULL;
         fprintf(stderr, "userName='%s'\n'", userName);
         if (!userName)
             {
             errAbort("not logged in");
             }
         else
             {
             // NOTE: All Upload.MetaData values are strings
             fileName = cgiEncodeFull(jsonQueryString(req, "", "Event.Upload.MetaData.fileName", NULL));
             fileSize = jsonQueryInt(req, "",  "Event.Upload.Size", 0, NULL);
             fileType = jsonQueryString(req, "", "Event.Upload.MetaData.fileType", NULL);
             db = jsonQueryString(req, "", "Event.Upload.MetaData.genome", NULL);
             reqLm = jsonQueryString(req, "", "Event.Upload.MetaData.lastModified", NULL);
             lastModified = sqlLongLong(reqLm) / 1000; // yes Javascript dates are in millis
             parentDir = jsonQueryString(req, "", "Event.Upload.MetaData.parentDir", NULL);
-            reqHubName = cgiEncodeFull(jsonQueryString(req, "", "Event.Upload.MetaData.hubName", NULL));
+            fprintf(stderr, "parentDir = '%s'\n", parentDir);
+            fflush(stderr);
+            // strip out plain leading '.' and '/' components
+            // middle '.' components are dealt with later
+            if (startsWith("./", parentDir) || startsWith("/", parentDir))
+                parentDir = skipBeyondDelimit(parentDir, '/');
+            fprintf(stderr, "parentDir = '%s'\n", parentDir);
+            fflush(stderr);
             char *tusFile = jsonQueryString(req, "", "Event.Upload.Storage.Path", NULL);
             if (fileName == NULL)
                 {
                 errAbort("No Event.Upload.fileName setting");
                 }
             else if (tusFile == NULL)
                 {
                 errAbort("No Event.Path setting");
                 }
             else
                 {
                 char *tusInfo = catTwoStrings(tusFile, ".info");
                 char *dataDir = getDataDir(userName);
                 struct dyString *newFile = dyStringNew(0);
-                // if hubName is provided that becomes the top level directory
-                if (reqHubName)
-                    dataDir = catTwoStrings(dataDir, catTwoStrings(reqHubName, "/"));
                 // if parentDir provided we are throwing the files in there
                 if (parentDir)
                     {
                     if (!endsWith(parentDir, "/"))
                         parentDir = catTwoStrings(parentDir, "/");
                     dataDir = catTwoStrings(dataDir, parentDir);
                     }
                 dyStringPrintf(newFile, "%s%s", dataDir, fileName);
 
                 fprintf(stderr, "moving %s to %s\n", tusFile, dyStringContents(newFile));
                 // TODO: check if file exists or not and let user choose to overwrite
                 // and re-call this hook, for now just exit if the file exists
                 if (fileExists(dyStringContents(newFile)))
                     {
                     errAbort("file '%s' exists already, not overwriting", dyStringContents(newFile));
@@ -148,48 +151,47 @@
                     copyFile(tusFile, dyStringContents(newFile));
                     // the files definitely should not be executable!
                     chmod(dyStringContents(newFile), 0666);
                     mustRemove(tusFile);
                     mustRemove(tusInfo);
                     dyStringCannibalize(&newFile);
                     }
                 }
             }
 
         // we've passed all the checks so we can write a new or updated row
         // to the mysql table and return to the client that we were successful
         if (exitStatus == 0)
             {
             // create a hub for this upload, which can be edited later
-            createNewTempHubForUpload(reqId, userName, db, fileName, fileType, reqHubName, parentDir);
+            createNewTempHubForUpload(reqId, userName, db, fileName, fileType, parentDir);
             fprintf(stderr, "added hub.txt and hubSpace row for hub for file: '%s'\n", fileName);
             fflush(stderr);
             struct hubSpace *row = NULL;
             AllocVar(row);
             row->userName = userName;
             row->fileName = fileName;
             row->fileSize = fileSize;
             row->fileType = fileType;
             row->creationTime = NULL; // automatically handled by mysql
             row->lastModified = sqlUnixTimeToDate(&lastModified, TRUE);
             row->parentDir = parentDir;
             row->db = db;
             row->location = location;
             row->md5sum = md5HexForFile(row->location);
             row->parentDir = parentDir ? parentDir : "";
             addHubSpaceRowForFile(row);
-            hubSpaceFree(&row);
             fprintf(stderr, "added hubSpace row for file '%s'\n", fileName);
             fflush(stderr);
             }
         }
     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 exitStatus;
 }