7ba5c812bda048b28ade940e0030b8000a02ae4b chmalee Mon Aug 10 11:58:51 2026 -0700 hubSpace: key rows on location so two hubs can hold the same file name, refs #37964 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> diff --git src/hg/inc/userdata.h src/hg/inc/userdata.h index 31d26898351..f49fe48a6c2 100644 --- src/hg/inc/userdata.h +++ src/hg/inc/userdata.h @@ -63,64 +63,67 @@ /* Strips the getDataDir(userName) off of fname */ char *swapDataDir(char *userName, char *in); /* Try replacing the current dataDir with what is defined in hg.conf:tusdMountPoint as * the data server may be somewhere else and mounted over NFS. In this case, when * tusd saves files, it is writing it's local tusdDataDir value into the hgcentral * file location. When the CGI running somewhere else needs to verify file existence, * the tusdDataDir won't exist on the CGI filesystem, but will instead be mounted as some * different path. In this case, replace tusdDataDir with tusdMountPoint */ char *prefixUserFile(char *userName, char *fname, char *parentDir); /* Allocate a new string that contains the full per-user path to fname. return NULL if * we cannot construct a full path because of a realpath(3) failure. * parentDir is optional and will go in between the per-user dir and the fname */ -char *hubNameFromPath(char *path); -/* Return the last directory component of path. Assume that a '.' char in the last component - * means that component is a filename and go back further */ +char *hubLeafFromPath(char *path); +/* Return the last '/' separated component of path, ignoring a trailing '/'. Callers + * pass a directory, so there is no filename to guess at: a '.' in the last component + * is part of a directory name, which isValidParentDir allows */ char *hubRootFromParentDir(char *parentDir); /* Return the first '/' separated component of parentDir, which is the hub itself. * The hub.txt and the hubSpace dir row for a hub both live at that level, while - * hubNameFromPath gives the immediately containing directory, which for a nested + * hubLeafFromPath gives the immediately containing directory, which for a nested * parentDir like 'myHub/hg38' is a subdirectory of the hub */ char *hubPathFromParentDir(char *parentDir, char *userDataDir); /* Return the directory holding this hub's hub.txt, that is the user's directory * plus the hub component of parentDir */ char *writeHubText(char *path, char *userName, char *db, char *twoBitFileName); /* Create a hub.txt file, optionally creating the directory holding it. * If twoBitFileName is non-NULL, write an assembly hub stanza referencing it * (with stub organism / scientificName / description / defaultPos derived from * the 2bit). For convenience, return the file name of the created hub, which * can be freed. */ void createNewTempHubForUpload(char *requestId, struct hubSpace *rowForFile, char *userDataDir); /* Creates a hub.txt for this upload, and updates the hubSpace table for the * hub.txt and any parentDirs we need to create. */ -boolean userHasOwnNamedHubTxtInDir(char *userName, char *parentDir); -/* Return TRUE if user uploaded a *.hub.txt NOT literally named 'hub.txt' in parentDir. - * Used to decide whether the backend can modify hub.txt (synthesize / append / upgrade) - * or should leave it alone because the user has their own authoritative config. */ +boolean userHasOwnNamedHubTxtInDir(char *userName, char *hubName, char *hubDir); +/* Return TRUE if the user uploaded a *.hub.txt file NOT literally named 'hub.txt' + * (e.g. 'araTha1.hub.txt') at the top level of hubDir. Distinguishes "user's own + * authoritative hub.txt" from "backend-synthesized hub.txt that we're free to modify". + * parentDir alone would also match a *.hub.txt sitting in some other hub's + * subdirectory that happens to be named hubName, so pin it to hubDir as well */ char *existingHubTypeForDir(char *userName, char *hubName); /* Return the hubType of this user's hub dir row, or NULL if no such row exists. */ -void upgradeExistingHubToAssembly(struct hubSpace *rowForFile, char *userDataDir, char *encodedParentDir); +void upgradeExistingHubToAssembly(struct hubSpace *rowForFile, char *userDataDir); /* Race-proofing: when a 2bit arrives into a hub that already has a synthesized * hub.txt, upgrade that hub.txt to include the assembly stanza and mark every * hubSpace row for this hub as hubType='assemblyHub'. No-op unless rowForFile * is a 2bit, or the synthesized hub.txt does not exist. */ int lockHubDir(char *hubDir); /* Acquire an exclusive flock on hubDir/.hub.lock; returns a file descriptor. * Hold while mutating hub.txt to serialize parallel pre-finish processes. */ void unlockHubDir(int fd); /* Release an exclusive hub lock acquired by lockHubDir. */ void addHubSpaceRowForFile(struct hubSpace *row); /* We created a file for a user, now add an entry to the hubSpace table for it */