7545a188d43c6e1ea33f692b0d833ec96a7f76c5
chmalee
  Wed Aug 14 09:21:15 2024 -0700
refactor some methods into userdata.c for writing hub.txt files. Finish trackHubWizard.c back end for writing hub.txt and clean up the html. Start of adding a modal dialog for creating hub.txt

diff --git src/hg/lib/userdata.c src/hg/lib/userdata.c
index 7b75f1b..b8adde5 100644
--- src/hg/lib/userdata.c
+++ src/hg/lib/userdata.c
@@ -79,30 +79,64 @@
     retUrl = dyStringCannibalize(&userDirDy);
     }
 return retUrl;
 }
 
 char *prefixUserFile(char *userName, char *fname)
 /* Allocate a new string that contains the full per-user path to fname, NULL otherwise */
 {
 char *pathPrefix = getDataDir(userName);
 if (pathPrefix)
     return catTwoStrings(pathPrefix, fname);
 else
     return NULL;
 }
 
+void addNewFileForUser(char *userName, char *fileName, long long fileSize, char *fileType,
+        time_t lastModified, char *hubName, char *db, char *location)
+/* We created a file for a user, now add an entry to the hubSpace table for it */
+{
+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->hubNameList = hubName;
+row->db = db;
+row->location = location;
+row->md5sum = md5HexForFile(row->location);
+struct sqlConnection *conn = hConnectCentral();
+
+// now write out row to hubSpace table
+if (!sqlTableExistsOnMain(conn, "hubSpace"))
+    {
+    errAbort("No hubSpace MySQL table is present. Please send an email to us describing the steps you took just before you got this error");
+    }
+struct dyString *sqlUpdateStmt = dyStringNew(0);
+sqlDyStringPrintf(sqlUpdateStmt, "insert into hubSpace values ('%s', '%s', %llu, "
+        "'%s', NULL, '%s', '', '%s', '%s', '%s')",
+        row->userName, row->fileName, row->fileSize, row->fileType,
+        row->lastModified, row->db, row->location, row->md5sum);
+fprintf(stderr, "%s\n", sqlUpdateStmt->string);
+fflush(stderr);
+sqlUpdate(conn, sqlUpdateStmt->string);
+hubSpaceFree(&row);
+}
+
 void removeFileForUser(char *fname, char *userName)
 /* Remove a file for this user if it exists */
 {
 // The file to remove must be prefixed by the hg.conf userDataDir
 if (!startsWith(getDataDir(userName), fname))
     return;
 if (fileExists(fname))
     {
     // delete the actual file
     mustRemove(fname);
     // delete the table row
     struct sqlConnection *conn = hConnectCentral();
     struct dyString *deleteQuery = sqlDyStringCreate("delete from hubSpace where location='%s'", fname);
     sqlUpdate(conn, dyStringCannibalize(&deleteQuery));
     }