979ae40501044410b8375bdb5840dcdfcb70c712
chmalee
  Wed Oct 2 12:26:27 2024 -0700
Working hub deletion

diff --git src/hg/lib/userdata.c src/hg/lib/userdata.c
index b8adde5..07438a7 100644
--- src/hg/lib/userdata.c
+++ src/hg/lib/userdata.c
@@ -113,44 +113,66 @@
 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);
 }
 
+static void deleteHubSpaceRow(char *fname)
+/* Deletes a row from the hubspace table for a given fname */
+{
+struct sqlConnection *conn = hConnectCentral();
+struct dyString *deleteQuery = sqlDyStringCreate("delete from hubSpace where location='%s'", fname);
+sqlUpdate(conn, dyStringCannibalize(&deleteQuery));
+}
+
 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));
+    deleteHubSpaceRow(fname);
+    }
+}
+
+void removeHubForUser(char *path, char *userName)
+/* Remove a hub directory for this user (and all files in the directory), if it exists */
+{
+if (!startsWith(getDataDir(userName), path))
+    return;
+if (isDirectory(path))
+    {
+    struct fileInfo *f, *flist = listDirX(path, NULL, TRUE);
+    for (f = flist; f != NULL; f = f->next)
+        mustRemove(f->name);
+    // now we have deleted all the files in the dir we can safely rmdir
+    mustRemove(path);
+    deleteHubSpaceRow(path);
     }
 }
 
 void uploadTrack()
 /* Saves a new track to the persistent storage for this user */
 {
 //char *userName = getUserName();
 }
 
 struct userFiles *listFilesForUserHub(char *userName, char *hubName)
 /* Get all the files for a particular hub for a particular user */
 {
 struct userFiles *userListing;
 AllocVar(userListing);
 char *path = getHubDataDir(userName, hubName);