src/lib/udc.c 1.17
1.17 2009/05/18 21:35:20 galt
refactored to all udcFileCacheFiles to operate without requiring the url to be actually opened
Index: src/lib/udc.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/udc.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -b -B -U 4 -r1.16 -r1.17
--- src/lib/udc.c 17 Apr 2009 19:41:26 -0000 1.16
+++ src/lib/udc.c 18 May 2009 21:35:20 -0000 1.17
@@ -603,26 +603,25 @@
}
return output;
}
-struct udcFile *udcFileMayOpen(char *url, char *cacheDir)
-/* Open up a cached file. Return NULL if file doesn't exist. */
+void udcParseUrl(char *url, char **retProtocol, char **retAfterProtocol, char **retColon)
+/* handle url parsing */
{
-verbose(2, "udcfileOpen(%s, %s)\n", url, cacheDir);
-/* Parse out protocol. Make it "transparent" if none specified. */
char *protocol, *afterProtocol;
char *colon = strchr(url, ':');
-struct udcProtocol *prot;
-boolean isTransparent = FALSE;
-if (colon != NULL)
+if (!colon)
{
- int colonPos = colon - url;
- protocol = cloneStringZ(url, colonPos);
- afterProtocol = url + colonPos + 1;
- while (afterProtocol[0] == '/')
+ *retColon = NULL;
+ return;
+ }
+int colonPos = colon - url;
+protocol = cloneStringZ(url, colonPos);
+afterProtocol = url + colonPos + 1;
+while (afterProtocol[0] == '/')
afterProtocol += 1;
- char *userPwd = strchr(afterProtocol, '@');
- if (userPwd)
+char *userPwd = strchr(afterProtocol, '@');
+if (userPwd)
{
char *afterHost = strchr(afterProtocol, '/');
if (!afterHost)
{
@@ -630,16 +629,41 @@
}
if (userPwd < afterHost)
afterProtocol = userPwd + 1;
}
- afterProtocol = qEncode(afterProtocol);
- }
-else
+afterProtocol = qEncode(afterProtocol);
+*retProtocol = protocol;
+*retAfterProtocol = afterProtocol;
+*retColon = colon;
+}
+
+void udcPathAndFileNames(struct udcFile *file, char *cacheDir, char *protocol, char *afterProtocol)
+/* Initialize udcFile path and names */
+{
+int len = strlen(cacheDir) + 1 + strlen(protocol) + 1 + strlen(afterProtocol) + 1;
+file->cacheDir = needMem(len);
+safef(file->cacheDir, len, "%s/%s/%s", cacheDir, protocol, afterProtocol);
+
+/* Create file names for bitmap and data portions. */
+file->bitmapFileName = fileNameInCacheDir(file, bitmapName);
+file->sparseFileName = fileNameInCacheDir(file, sparseDataName);
+}
+
+struct udcFile *udcFileMayOpen(char *url, char *cacheDir)
+/* Open up a cached file. Return NULL if file doesn't exist. */
+{
+verbose(2, "udcfileOpen(%s, %s)\n", url, cacheDir);
+/* Parse out protocol. Make it "transparent" if none specified. */
+char *protocol, *afterProtocol, *colon;
+boolean isTransparent = FALSE;
+udcParseUrl(url, &protocol, &afterProtocol, &colon);
+if (!colon)
{
protocol = cloneString("transparent");
afterProtocol = cloneString(url);
isTransparent = TRUE;
}
+struct udcProtocol *prot;
prot = udcProtocolNew(protocol);
/* Figure out if anything exists. */
struct udcRemoteFileInfo info;
@@ -672,19 +696,13 @@
file->endData = file->size = status.st_size;
}
else
{
- int len = strlen(cacheDir) + 1 + strlen(protocol) + 1 + strlen(afterProtocol) + 1;
- file->cacheDir = needMem(len);
- safef(file->cacheDir, len, "%s/%s/%s", cacheDir, protocol, afterProtocol);
+ udcPathAndFileNames(file, cacheDir, protocol, afterProtocol);
/* Make directory. */
makeDirsOnPath(file->cacheDir);
- /* Create file names for bitmap and data portions. */
- file->bitmapFileName = fileNameInCacheDir(file, bitmapName);
- file->sparseFileName = fileNameInCacheDir(file, sparseDataName);
-
/* Figure out a little bit about the extent of the good cached data if any. */
setInitialCachedDataBounds(file);
file->fSparse = mustOpen(file->sparseFileName, "rb+");
}
@@ -700,8 +718,28 @@
errAbort("Couldn't open %s", url);
return udcFile;
}
+
+struct slName *udcFileCacheFiles(char *url, char *cacheDir)
+/* Return low-level list of files used in cache. */
+{
+char *protocol, *afterProtocol, *colon;
+struct udcFile *file;
+udcParseUrl(url, &protocol, &afterProtocol, &colon);
+AllocVar(file);
+udcPathAndFileNames(file, cacheDir, protocol, afterProtocol);
+struct slName *list = NULL;
+slAddHead(&list, slNameNew(file->bitmapFileName));
+slAddHead(&list, slNameNew(file->sparseFileName));
+slReverse(&list);
+freeMem(file->cacheDir);
+freeMem(file->bitmapFileName);
+freeMem(file->sparseFileName);
+freeMem(file);
+return list;
+}
+
void udcFileClose(struct udcFile **pFile)
/* Close down cached file. */
{
struct udcFile *file = *pFile;