d8e35c06509da9ae47bc0064f22427600844a4f3
chmalee
  Wed Apr 2 14:15:26 2025 -0700
Fix cancel button not doing anything on file metadata editor, fix hub.txt upload to not create duplicate mysql rows, fix hub.txt upload to not create duplicate data-table ui rows, fix hub default name generator to not choke if a hub startsWith the default hub name but is not immediately followed by a number, refs #35383

diff --git src/hg/lib/userdata.c src/hg/lib/userdata.c
index 037fad2c074..efcbe4b6b49 100644
--- src/hg/lib/userdata.c
+++ src/hg/lib/userdata.c
@@ -391,44 +391,53 @@
 /* Return a name to use as a default for a hub, starts with defaultHub, then defaultHub2, ... */
 {
 if (!userName)
     return defaultHubName;
 struct dyString *query = sqlDyStringCreate("select distinct(fileName) from hubSpace where parentDir='' and fileName like '%s%%' and userName='%s'", defaultHubName, userName);
 struct sqlConnection *conn = hConnectCentral();
 struct slName *hubNames = sqlQuickList(conn, dyStringCannibalize(&query));;
 hDisconnectCentral(&conn);
 if (hubNames == NULL)
     // user has no hubs created
     return defaultHubName;
 slSort(&hubNames,slNameCmpStringsWithEmbeddedNumbers);
 slReverse(&hubNames);
 // now the first element of the list has the most recent integer to use (or no integer)
 char *currHubName = cloneString(hubNames->name);
-int currHubStrLen = strlen(currHubName);
 int defaultLen = strlen(defaultHubName);
-if (currHubStrLen == defaultLen)
+if (sameString(currHubName,defaultHubName))
     // probably a common case
     return "defaultHub2";
 else
     {
     currHubName[defaultLen-1] = 0;
     currHubName += strlen(defaultHubName);
+    eraseNonDigits(currHubName);
+    if (strlen(currHubName) == 0)
+        {
+        // user has a hub like defaultHubblah, just assume defaultHub2 is ok instead of
+        // going further and trying to figure out the next hub number
+        return "defaultHub2";
+        }
+    else
+        {
         int hubNum = sqlUnsigned(currHubName) + 1;
         struct dyString *hubName = dyStringCreate("%s%d", defaultHubName, hubNum);
         return dyStringCannibalize(&hubName);
         }
     }
+}
 
 long long getMaxUserQuota(char *userName)
 /* Return how much space is allocated for this user or the default */
 {
 long long specialQuota = quotaForUserName(userName);
 return specialQuota == 0 ? HUB_SPACE_DEFAULT_QUOTA : specialQuota;
 }
 
 long long checkUserQuota(char *userName)
 /* Return the amount of space a user is currently using */
 {
 long long quota = 0;
 struct hubSpace *hubSpace, *hubSpaceList = listFilesForUser(userName);
 for (hubSpace = hubSpaceList; hubSpace != NULL; hubSpace = hubSpace->next)
     {