/*------------------------------------------------------------------------- * Function: h5_cleanup * * Purpose: Cleanup temporary test files. * base_name contains the list of test file names. * The file access property list is also closed. * * Return: Non-zero if cleanup actions were performed; zero otherwise. * * Programmer: Albert Cheng * May 28, 1998 * *------------------------------------------------------------------------- */ int h5_cleanup(const char *base_name[], hid_t fapl) { int retval = 0; if(GetTestCleanup()) { int i; for(i = 0; base_name[i]; i++) { char filename[1024]; char temp[2048]; hid_t driver; if(NULL == h5_fixname(base_name[i], fapl, filename, sizeof(filename))) continue; driver = H5Pget_driver(fapl); if(driver == H5FD_FAMILY) { int j; for(j = 0; /*void*/; j++) { HDsnprintf(temp, sizeof temp, filename, j); if(HDaccess(temp, F_OK) < 0) break; HDremove(temp); } /* end for */ } else if(driver == H5FD_CORE) { hbool_t backing; /* Whether the core file has backing store */ H5Pget_fapl_core(fapl, NULL, &backing); /* If the file was stored to disk with bacing store, remove it */ if(backing) HDremove(filename); } else if (driver == H5FD_MULTI) { H5FD_mem_t mt; HDassert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES); for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) { HDsnprintf(temp, sizeof temp, "%s-%c.h5", filename, multi_letters[mt]); HDremove(temp); /*don't care if it fails*/ } /* end for */ } else { HDremove(filename); } } /* end for */ retval = 1; } /* end if */ H5Pclose(fapl); return retval; }
/*------------------------------------------------------------------------- * Function: h5_get_file_size * * Purpose: Get the current size of a file (in bytes) * * Return: Success: Size of file in bytes * Failure: -1 * * Programmer: Quincey Koziol * Saturday, March 22, 2003 * *------------------------------------------------------------------------- */ h5_stat_size_t h5_get_file_size(const char *filename, hid_t fapl) { char temp[2048]; /* Temporary buffer for file names */ h5_stat_t sb; /* Structure for querying file info */ int j = 0; if(fapl == H5P_DEFAULT) { /* Get the file's statistics */ if(0 == HDstat(filename, &sb)) return((h5_stat_size_t)sb.st_size); } /* end if */ else { hid_t driver; /* VFD used for file */ /* Get the driver used when creating the file */ if((driver = H5Pget_driver(fapl)) < 0) return(-1); /* Check for simple cases */ if(driver == H5FD_SEC2 || driver == H5FD_STDIO || driver == H5FD_CORE || #ifdef H5_HAVE_PARALLEL driver == H5FD_MPIO || #endif /* H5_HAVE_PARALLEL */ #ifdef H5_HAVE_WINDOWS driver == H5FD_WINDOWS || #endif /* H5_HAVE_WINDOWS */ #ifdef H5_HAVE_DIRECT driver == H5FD_DIRECT || #endif /* H5_HAVE_DIRECT */ driver == H5FD_LOG) { /* Get the file's statistics */ if(0 == HDstat(filename, &sb)) return((h5_stat_size_t)sb.st_size); } /* end if */ else if(driver == H5FD_MULTI) { H5FD_mem_t mt; h5_stat_size_t tot_size = 0; HDassert(HDstrlen(multi_letters) == H5FD_MEM_NTYPES); for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t, mt)) { /* Create the filename to query */ HDsnprintf(temp, sizeof temp, "%s-%c.h5", filename, multi_letters[mt]); /* Check for existence of file */ if(0 == HDaccess(temp, F_OK)) { /* Get the file's statistics */ if(0 != HDstat(temp, &sb)) return(-1); /* Add to total size */ tot_size += (h5_stat_size_t)sb.st_size; } /* end if */ } /* end for */ /* Return total size */ return(tot_size); } /* end if */ else if(driver == H5FD_FAMILY) { h5_stat_size_t tot_size = 0; /* Try all filenames possible, until we find one that's missing */ for(j = 0; /*void*/; j++) { /* Create the filename to query */ HDsnprintf(temp, sizeof temp, filename, j); /* Check for existence of file */ if(HDaccess(temp, F_OK) < 0) break; /* Get the file's statistics */ if(0 != HDstat(temp, &sb)) return(-1); /* Add to total size */ tot_size += (h5_stat_size_t)sb.st_size; } /* end for */ /* Return total size */ return(tot_size); } /* end if */ else { HDassert(0 && "Unknown VFD!"); } /* end else */ } /* end else */ return(-1); } /* end get_file_size() */
/* * Function: do_cleanupfile * Purpose: Cleanup temporary file unless HDF5_NOCLEANUP is set. * Return: void * Programmer: Albert Cheng 2001/12/12 * Modifications: Support for file drivers. Christian Chilan, April, 2008 */ static void do_cleanupfile(iotype iot, char *filename) { char temp[2048]; int j; hid_t driver; if (clean_file_g == -1) clean_file_g = (HDgetenv("HDF5_NOCLEANUP")==NULL) ? 1 : 0; if (clean_file_g){ switch (iot) { case POSIXIO: HDremove(filename); break; case HDF5: driver = H5Pget_driver(fapl); if (driver == H5FD_FAMILY) { for (j = 0; /*void*/; j++) { HDsnprintf(temp, sizeof temp, filename, j); if (HDaccess(temp, F_OK) < 0) break; HDremove(temp); } } else if (driver == H5FD_CORE) { hbool_t backing; /* Whether the core file has backing store */ H5Pget_fapl_core(fapl,NULL,&backing); /* If the file was stored to disk with bacing store, remove it */ if(backing) HDremove(filename); } else if (driver == H5FD_MULTI) { H5FD_mem_t mt; assert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES); for (mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) { HDsnprintf(temp, sizeof temp, "%s-%c.h5", filename, multi_letters[mt]); HDremove(temp); /*don't care if it fails*/ } } else { HDremove(filename); } H5Pclose(fapl); break; default: /* unknown request */ HDfprintf(stderr, "Unknown IO type request (%d)\n", (int)iot); HDassert(0 && "Unknown IO type"); break; } } }