979ae40501044410b8375bdb5840dcdfcb70c712 chmalee Wed Oct 2 12:26:27 2024 -0700 Working hub deletion diff --git src/hg/hgHubConnect/trackHubWizard.c src/hg/hgHubConnect/trackHubWizard.c index 60d961a..d164c80 100644 --- src/hg/hgHubConnect/trackHubWizard.c +++ src/hg/hgHubConnect/trackHubWizard.c @@ -21,47 +21,59 @@ #include "hubSpace.h" #include "hubConnect.h" void removeOneFile(char *userName, char *cgiFileName) /* Remove one single file for userName */ { char *fileName = prefixUserFile(userName, cgiEncodeFull(cgiFileName)); if (fileExists(fileName)) { fprintf(stderr, "deleting file: '%s'\n", fileName); removeFileForUser(fileName, userName); fflush(stderr); } } +void removeHubDir(char *userName, char *cgiFileName) +/* Remove one single file for userName */ +{ +char *fileName = prefixUserFile(userName, cgiEncodeFull(cgiFileName)); +if (fileExists(fileName)) + { + fprintf(stderr, "deleting file: '%s'\n", fileName); + removeHubForUser(fileName, userName); + fflush(stderr); + } +} + void doRemoveFile(struct cartJson *cj, struct hash *paramHash) /* Process the request to remove a file */ { char *userName = getUserName(); if (userName) { struct jsonElement *deleteJson = hashFindVal(paramHash, "fileNameList"); //struct jsonWrite *errors = jsonWriteNew(); // TODO: Check request is well-formed - struct slRef *ele, *deleteList = deleteJson->val.jeList; + char *fname = ((struct jsonElement *)(deleteJson->val.jeList->val))->val.jeString; + boolean isHub = sameString("hub", ((struct jsonElement *)(deleteJson->val.jeList->next->val))->val.jeString); jsonWriteListStart(cj->jw, "deletedList"); - for (ele = deleteList; ele != NULL; ele = ele->next) - { - struct jsonElement *jsonVal = ele->val; - removeOneFile(userName, jsonVal->val.jeString); - jsonWriteString(cj->jw, NULL, jsonVal->val.jeString); - } + if (isHub) + removeHubDir(userName, fname); + else + removeOneFile(userName, fname); + jsonWriteString(cj->jw, NULL, fname); jsonWriteListEnd(cj->jw); } } void doMoveFile(struct cartJson *cj, struct hash *paramHash) /* Move a file to a new hub */ { } static void writeHubText(char *path, char *userName, char *hubName, char *db) /* Create a hub.txt file, optionally creating the directory holding it */ { int oldUmask = 00; oldUmask = umask(0); makeDirsOnPath(path); @@ -81,47 +93,48 @@ carefulClose(&f); } void doCreateHub(struct cartJson *cj, struct hash *paramHash) /* Make a new hub.txt with the parameters from the JSON request */ { char *userName = getUserName(); if (userName) { struct jsonWrite *errors = jsonWriteNew(); // verify the arguments: (void)cartJsonRequiredParam(paramHash, "createHub", errors, "doCreateHub"); // paramHash is an object with everything necessary to create a hub: name and assembly char *db = jsonStringVal(hashFindVal(paramHash, "db"), "db"); char *name = jsonStringVal(hashFindVal(paramHash, "name"), "name"); - fprintf(stderr, "creating hub '%s' for db '%s'\n", name, db); + char *encodedName = cgiEncodeFull(name); + fprintf(stderr, "creating hub '%s' for db '%s'\n", encodedName, db); fflush(stderr); // check if this hub already exists, must have a directory and hub.txt already: - char *path = prefixUserFile(userName, name); + char *path = prefixUserFile(userName, encodedName); if (isDirectory(path)) { // can't make a hub that already exists! fprintf(stdout, "Status: 400 Bad Request\n\n"); fprintf(stdout, "Hub already exists, select hub from dropdown or try a different name"); fflush(stdout); exit(1); } else { // good we can make a new directory and stuff a hub.txt in it // the directory needs to be 777, so ignore umask for now - writeHubText(path, userName, name, db); + writeHubText(path, userName, encodedName, db); // TODO: add a row to the hubspace table for the hub.txt //addHubTxtToTable(userName, path, name, db); // return json to fill out the table jsonWriteString(cj->jw, "hubName", name); jsonWriteString(cj->jw, "db", db); time_t now = time(NULL); jsonWriteString(cj->jw, "creationTime", sqlUnixTimeToDate(&now, FALSE)); } } } static void outFilesForUser() /* List out the currently stored files for the user and their sizes */ { char *userName = getUserName();