82d5a7df56ab88caf3b48255b242c5b3211cc6a6
jcasper
  Fri Jul 16 16:47:01 2021 -0700
Fixing UDC to use TMPDIR when defined instead of /tmp, no ticket

diff --git src/lib/udc.c src/lib/udc.c
index c1071f9..a5e8ac3 100644
--- src/lib/udc.c
+++ src/lib/udc.c
@@ -420,47 +420,67 @@
 char *fileName = url + 5;  /* skip over 'slow:' */
 verbose(4, "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 char *defaultDir = "/tmp/udcCache";
+static bool udcInitialized = FALSE;
+
+static void initializeUdc()
+/* Use the $TMPDIR environment variable, if set, to amend the default location
+ * of the cache */
+{
+if (udcInitialized)
+    return;
+char *tmpDir = getenv("TMPDIR");
+if (isNotEmpty(tmpDir))
+    {
+    char buffer[2048];
+    safef(buffer, sizeof(buffer), "%s/udcCache", tmpDir);
+    udcSetDefaultDir(buffer);
+    }
+}
 
 char *udcDefaultDir()
 /* Get default directory for cache */
 {
+if (!udcInitialized)
+    initializeUdc();
 return defaultDir;
 }
 
 void udcSetDefaultDir(char *path)
 /* Set default directory for cache.  */
 {
 defaultDir = cloneString(path);
+udcInitialized = TRUE;
 }
 
 void udcDisableCache()
 /* Switch off caching. Re-enable with udcSetDefaultDir */
 {
 defaultDir = NULL;
+udcInitialized = TRUE;
 }
 
 static bool udcCacheEnabled()
 /* TRUE if caching is activated */
 {
 return (defaultDir != NULL);
 }
 
 int udcDataViaHttpOrFtp( char *url, bits64 offset, int size, void *buffer, struct udcFile *file)
 /* 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))