7864ddf3a6d058dbe29f706519921cd55ccc4c67 chmalee Thu May 2 09:04:45 2024 -0700 Work in progress on building form for choosing db and hub along with files to submit diff --git src/hg/lib/userdata.c src/hg/lib/userdata.c index fe141aa..f25fc29 100644 --- src/hg/lib/userdata.c +++ src/hg/lib/userdata.c @@ -32,30 +32,36 @@ if (userDataBaseDir[0] != '/') errAbort("config setting userDataDir must be an absolute path (starting with '/')"); char *encUserName = cgiEncode(userName); char *userPrefix = md5HexForString(encUserName); userPrefix[2] = '\0'; struct dyString *newDataDir = dyStringNew(0); dyStringPrintf(newDataDir, "%s/%s/%s/", userDataBaseDir, userPrefix, encUserName); fprintf(stderr, "userDataDir = '%s'\n", newDataDir->string); return dyStringCannibalize(&newDataDir); } +char *getHubDataDir(char *userName, char *hub) +{ +char *dataDir = getDataDir(userName); +return catTwoStrings(dataDir, hub); +} + char *webDataDir(char *userName) /* Return a web accesible path to the userDataDir, this is different from the full path tusd uses */ { char *retUrl = NULL; if (userName) { char *encUserName = cgiEncode(userName); char *userPrefix = md5HexForString(encUserName); userPrefix[2] = '\0'; struct dyString *userDirDy = dyStringNew(0); dyStringPrintf(userDirDy, "%s/%s/%s/", HUB_SPACE_URL, userPrefix, encUserName); retUrl = dyStringCannibalize(&userDirDy); } return retUrl; } @@ -74,55 +80,83 @@ /* 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)) mustRemove(fname); } void uploadTrack() /* Saves a new track to the persistent storage for this user */ { //char *userName = getUserName(); } -struct userFiles *listFilesForUser(char *userName) -/* Get all the files for a particular user */ +struct userHubs *listHubsForUser(char *userName) +/* Lists the directories for a particular user */ +{ +struct userHubs *userHubs = NULL; +char *path = getDataDir(userName); +struct fileInfo *fi, *fiList = listDirX(path,NULL,FALSE); +for (fi = fiList; fi != NULL; fi = fi->next) + { + if (fi->isDir) + { + struct userHubs *hub; + AllocVar(hub); + hub->hubName = cloneString(fi->name); + hub->userName = cloneString(userName); + char hubPath[PATH_LEN]; + safef(hubPath, sizeof(hubPath), "%s%s", path, fi->name); + struct userFiles *hubFileList = listFilesForUserHub(userName, hub->hubName); + hub->fileList = hubFileList; + slAddHead(&userHubs, hub); + } + } +return userHubs; +} + +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 = getDataDir(userName); +char *path = getHubDataDir(userName, hubName); struct fileInfo *fiList = listDirX(path,NULL,FALSE); userListing->userName = userName; -userListing->file = fiList; +userListing->fileList = fiList; return userListing; } long long checkUserQuota(char *userName) /* Return the amount of space a user is currently using */ { long long quota = 0; -struct userFiles *ufList = listFilesForUser(userName); +struct userHubs *hub, *userHubs = listHubsForUser(userName); +for (hub = userHubs; hub != NULL; hub = hub->next) + { + struct userFiles *ufList = listFilesForUserHub(userName, hub->hubName); struct fileInfo *fi; if (ufList) { - for (fi = ufList->file; fi != NULL; fi = fi->next) + for (fi = ufList->fileList; fi != NULL; fi = fi->next) { quota += fi->size; } } + } return quota; } char *storeUserFile(char *userName, char *newFileName, void *data, size_t dataSize) /* Give a fileName and a data stream, write the data to: * userDataDir/hashedUserName/userName/fileName * where userDataDir comes from hg.conf and * hashedUserName is based on the md5sum of the userName * to prevent proliferation of too many directories. * * After sucessfully saving the file, return a web accessible url * to the file. */ { char *userDir = getDataDir(userName); makeDirsOnPath(userDir);