From 825300c9c4ed4d71761065a53ae078bdf94c8647 Mon Sep 17 00:00:00 2001 From: Cyrus Harrison Date: Tue, 10 Mar 2020 14:51:52 -0700 Subject: [PATCH] relay hdf5: use H5F_ACC_RDONLY for is_hdf5_file helper (#518) * relay hdf5: use H5F_ACC_RDONLY for is_hdf5_file * update changelog --- CHANGELOG.md | 4 ++++ src/libs/relay/conduit_relay_io_hdf5.cpp | 9 +++++++-- src/tests/relay/t_relay_io_hdf5.cpp | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe898646f..567997580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s - Updated to BLT v0.3.0 to resolve BLT/FindMPI issues with rpath linking commands when using OpenMPI. +#### Relay +- Use H5F_ACC_RDONLY in relay::io::is_hdf5_file to avoid errors when checking files that already have open HDF5 handles. + + ## [0.5.1] - Released 2020-01-18 ### Added diff --git a/src/libs/relay/conduit_relay_io_hdf5.cpp b/src/libs/relay/conduit_relay_io_hdf5.cpp index 630c30239..e39a61348 100644 --- a/src/libs/relay/conduit_relay_io_hdf5.cpp +++ b/src/libs/relay/conduit_relay_io_hdf5.cpp @@ -2632,9 +2632,14 @@ is_hdf5_file(const std::string &file_path) HDF5ErrorStackSupressor supress_hdf5_errors; bool res = false; - // open the hdf5 file for read + write + // open the file for read to check if it is valid hdf5 + // + // don't use H5F_ACC_RDWR, b/c if we already have a file handle open + // that is RDONLY, the open will fail + // + // use H5F_ACC_RDONLY b/c it will work with open file handles hid_t h5_file_id = H5Fopen(file_path.c_str(), - H5F_ACC_RDWR, + H5F_ACC_RDONLY, H5P_DEFAULT); if( h5_file_id >= 0) diff --git a/src/tests/relay/t_relay_io_hdf5.cpp b/src/tests/relay/t_relay_io_hdf5.cpp index 3db898868..860d9a396 100644 --- a/src/tests/relay/t_relay_io_hdf5.cpp +++ b/src/tests/relay/t_relay_io_hdf5.cpp @@ -995,6 +995,15 @@ TEST(conduit_relay_io_hdf5, check_if_file_is_hdf5_file) // this should be recoged as hdf5 EXPECT_TRUE(io::is_hdf5_file(tout)); + // check behavior with files that have open handles + hid_t h5_file_id = io::hdf5_open_file_for_read_write(tout); + EXPECT_TRUE(io::is_hdf5_file(tout)); + io::hdf5_close_file(h5_file_id); + + h5_file_id = io::hdf5_open_file_for_read(tout); + EXPECT_TRUE(io::is_hdf5_file(tout)); + io::hdf5_close_file(h5_file_id); + tout = "tout_hdf5_check_non_hdf5_file.json"; if(utils::is_file(tout)) @@ -1010,6 +1019,7 @@ TEST(conduit_relay_io_hdf5, check_if_file_is_hdf5_file) // check totally bad path EXPECT_FALSE(io::is_hdf5_file("/path/to/somewhere/that/cant/exist")); + }