821d259106b8cb1a8ddbdf52c929a1910e1b3848 max Tue Apr 14 05:40:34 2015 -0700 changes after code review, refs #15164 diff --git src/lib/udc.c src/lib/udc.c index d40b845..cccfadf 100644 --- src/lib/udc.c +++ src/lib/udc.c @@ -314,31 +314,55 @@ { char *fileName = url + 5; /* skip over 'slow:' */ verbose(2, "slow checking remote info on %s\n", url); sleep1000(500); struct stat status; int ret = stat(fileName, &status); if (ret < 0) return FALSE; retInfo->updateTime = status.st_mtime; retInfo->size = status.st_size; return TRUE; } /********* Section for http protocol **********/ -static bool udcCacheEnabled(); // forward declaration +static char *defaultDir = "/tmp/udcCache"; + +char *udcDefaultDir() +/* Get default directory for cache */ +{ +return defaultDir; +} + +void udcSetDefaultDir(char *path) +/* Set default directory for cache. */ +{ +defaultDir = cloneString(path); +} + +void udcDisableCache() +/* Switch off caching. Re-enable with udcSetDefaultDir */ +{ +defaultDir = NULL; +} + +static bool udcCacheEnabled() +/* TRUE if caching is activated */ +{ +return (defaultDir != NULL); +} int udcDataViaHttpOrFtp(char *url, bits64 offset, int size, void *buffer, struct connInfo *ci) /* Fetch a block of data of given size into buffer using url's protocol, * which must be http, https or ftp. Returns number of bytes actually read. * Does an errAbort on error. * Typically will be called with size in the 8k-64k range. */ { if (startsWith("http://",url) || startsWith("https://",url) || startsWith("ftp://",url)) verbose(2, "reading http/https/ftp data - %d bytes at %lld - on %s\n", size, offset, url); else errAbort("Invalid protocol in url [%s] in udcDataViaFtp, only http, https, or ftp supported", url); int sd = connInfoGetSocket(ci, url, offset, size); if (sd < 0) errAbort("Can't get data socket for %s", url); @@ -1650,56 +1674,30 @@ bits64 udcCleanup(char *cacheDir, double maxDays, boolean testOnly) /* Remove cached files older than maxDays old. If testOnly is set * no clean up is done, but the size of the files that would be * cleaned up is still. */ { time_t maxSeconds = maxDays * 24 * 60 * 60; char *curPath = cloneString(getCurrentDir()); setCurrentDir(cacheDir); time_t deleteTime = time(NULL) - maxSeconds; bits64 result = rCleanup(deleteTime, testOnly); setCurrentDir(curPath); return result; } -static char *defaultDir = "/tmp/udcCache"; - -char *udcDefaultDir() -/* Get default directory for cache */ -{ -return defaultDir; -} - -void udcSetDefaultDir(char *path) -/* Set default directory for cache. */ -{ -defaultDir = cloneString(path); -} - -void udcDisableCache() -/* Switch off caching. Re-enable with udcSetDefaultDir */ -{ -defaultDir = NULL; -} - -static bool udcCacheEnabled() -/* TRUE if caching is activated */ -{ -return (defaultDir != NULL); -} - int udcCacheTimeout() /* Get cache timeout (if local cache files are newer than this many seconds, * we won't ping the remote server to check the file size and update time). */ { return cacheTimeout; } void udcSetCacheTimeout(int timeout) /* Set cache timeout (if local cache files are newer than this many seconds, * we won't ping the remote server to check the file size and update time). */ { cacheTimeout = timeout; } time_t udcUpdateTime(struct udcFile *udc)