3a88c02326aadbb1df3436cd519f7b8a4df6ae5b chmalee Thu Jun 6 15:32:15 2024 -0700 Work in progress using the mysql table for hubSpace on client side diff --git src/hg/lib/userdata.c src/hg/lib/userdata.c index 810cefe..8f23157 100644 --- src/hg/lib/userdata.c +++ src/hg/lib/userdata.c @@ -3,30 +3,33 @@ /* Copyright (C) 2014 The Regents of the University of California * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */ #include "common.h" #include "hash.h" #include "portable.h" #include "trashDir.h" #include "md5.h" #include "hgConfig.h" #include "dystring.h" #include "cheapcgi.h" #include "customFactory.h" #include "wikiLink.h" #include "userdata.h" +#include "jksql.h" +#include "hdb.h" +#include "hubSpace.h" char *getUserName() { return (loginSystemEnabled() || wikiLinkEnabled()) ? wikiLinkUserName() : NULL; } char *getDataDir(char *userName) /* Return the full path to the user specific data directory, can be configured via hg.conf * on hgwdev, this is /data/apache/userdata/userStore/hash/userName/ * on the RR, this is /userdata/userStore/hash/userName/ */ { char *userDataBaseDir = cfgOption("userDataDir"); if (!userDataBaseDir || isEmpty(userDataBaseDir)) errAbort("trying to save user file but no userDataDir defined in hg.conf"); if (userDataBaseDir[0] != '/') @@ -71,97 +74,105 @@ { char *pathPrefix = getDataDir(userName); if (pathPrefix) return catTwoStrings(pathPrefix, fname); else return NULL; } 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)); + } } 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); +struct fileInfo *fiList = listDirX(path,NULL,FALSE); +userListing->userName = userName; +userListing->fileList = fiList; +return userListing; +} + 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 hubSpace *listFilesForUser(char *userName) +/* Return the files the user has uploaded */ { -struct userFiles *userListing; -AllocVar(userListing); -char *path = getHubDataDir(userName, hubName); -struct fileInfo *fiList = listDirX(path,NULL,FALSE); -userListing->userName = userName; -userListing->fileList = fiList; -return userListing; +struct sqlConnection *conn = hConnectCentral(); +struct dyString *query = sqlDyStringCreate("select * from hubSpace where userName='%s' order by creationTime, fileName", userName); +struct hubSpace *fileList = hubSpaceLoadByQuery(conn, dyStringCannibalize(&query)); +return fileList; } long long getMaxUserQuota(char *userName) /* Return how much space is allocated for this user or the default */ { return HUB_SPACE_DEFAULT_QUOTA; } long long checkUserQuota(char *userName) /* Return the amount of space a user is currently using */ { long long quota = 0; -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) +struct hubSpace *hubSpace, *hubSpaceList = listFilesForUser(userName); +for (hubSpace = hubSpaceList; hubSpace != NULL; hubSpace = hubSpace->next) { - for (fi = ufList->fileList; fi != NULL; fi = fi->next) - { - quota += fi->size; - } - } + quota += hubSpace->fileSize; } 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);