93da8e484fb9b77966db0f22b363130bf77be8b2
galt
  Fri Feb 14 01:05:11 2014 -0800
Partly fixes #12648. Helps clear the cache when truncated bitmap files get stuck in the system.
diff --git src/lib/udc.c src/lib/udc.c
index befbf3d..484b3d6 100644
--- src/lib/udc.c
+++ src/lib/udc.c
@@ -517,30 +517,35 @@
  * exist, abort on error. */
 {
 /* Open file, returning NULL if can't. */
 int fd = open(fileName, O_RDWR);
 if (fd < 0)
     {
     if (errno == ENOENT)
 	return NULL;
     else
 	errnoAbort("Can't open(%s, O_RDWR)", fileName);
     }
 
 /* Get status info from file. */
 struct stat status;
 fstat(fd, &status);
+if (status.st_size < udcBitmapHeaderSize) // check for truncated invalid bitmap files.
+    {
+    close(fd);
+    return NULL;  // returning NULL will cause the fresh creation of bitmap and sparseData files.
+    }  
 
 /* Read signature and decide if byte-swapping is needed. */
 // TODO: maybe buffer the I/O for performance?  Don't read past header - 
 // fd offset needs to point to first data block when we return.
 bits32 magic;
 boolean isSwapped = FALSE;
 mustReadOneFd(fd, magic);
 if (magic != udcBitmapSig)
     {
     magic = byteSwap32(magic);
     isSwapped = TRUE;
     if (magic != udcBitmapSig)
        errAbort("%s is not a udcBitmap file", fileName);
     }