Skip to content

Commit

Permalink
relay hdf5: use H5F_ACC_RDONLY for is_hdf5_file helper (#518)
Browse files Browse the repository at this point in the history
* relay hdf5: use H5F_ACC_RDONLY for is_hdf5_file

* update changelog
  • Loading branch information
cyrush committed Mar 10, 2020
1 parent df235cd commit 825300c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/libs/relay/conduit_relay_io_hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/tests/relay/t_relay_io_hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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"));

}


Expand Down

0 comments on commit 825300c

Please sign in to comment.