Skip to content

Commit

Permalink
Search for same name HDF5 file when rel file to HDF5 fails
Browse files Browse the repository at this point in the history
Fix #319
  • Loading branch information
philippeVerney committed May 22, 2024
1 parent aa5f398 commit 6c897ef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
/cs/example/Program.cs
/cs/example/HdfProxyFactoryExample.cs
/cs/example/HdfProxyExample.cs
/cs/EtpClientExample/EtpClientExample.cs
/cs/EtpClientExample/MyOwnClientCoreHandlers.cs
/cs/EtpClientExample/MyOwnDiscoveryProtocolHandlers.cs
/cs/EtpClientExample/MyOwnStoreProtocolHandlers.cs
/swig/swigCsInclude.i
/swig/swigJavaInclude.i
/swig/swigPythonInclude.i
Expand Down
2 changes: 1 addition & 1 deletion java/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Included in ../src/CmakeLists.txt if java build is selected.
# Included in ../src/CMakeLists.txt if java build is selected.

find_package(SWIG 3.0 REQUIRED)

Expand Down
1 change: 1 addition & 0 deletions src/common/AbstractObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,7 @@ EML2_NS::AbstractHdfProxy* AbstractObject::getOrCreateHdfProxyFromDataArrayPart(
#if WITH_RESQML2_2
if (hdfProxy == nullptr) {
hdfProxy = new EML2_3_NS::HdfProxy(getRepository(), "", "Fake eml23 HDF Proxy", getEpcSourceFolder(), dataArrayPart->URI);
hdfProxy->setUriSource(getUriSource());
getRepository()->addDataObject(hdfProxy);
}
#endif
Expand Down
35 changes: 22 additions & 13 deletions src/eml2/HdfProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,31 @@ void HdfProxy::open()
? packageDirectoryAbsolutePath
: packageDirectoryAbsolutePath + '/') + relativeFilePath;
if (openingMode == COMMON_NS::DataObjectRepository::openingMode::READ_ONLY || openingMode == COMMON_NS::DataObjectRepository::openingMode::READ_WRITE_DO_NOT_CREATE) {
if (H5Fis_hdf5(fullName.c_str()) > 0) {
hdfFile = H5Fopen(fullName.c_str(),
openingMode == COMMON_NS::DataObjectRepository::openingMode::READ_ONLY ? H5F_ACC_RDONLY : H5F_ACC_RDWR,
H5P_DEFAULT);
if (hdfFile < 0) {
throw invalid_argument("HDF5 library recognizes the HDF5 file but can not open it : " + fullName);
string replacedName = fullName;
if (H5Fis_hdf5(fullName.c_str()) <= 0) {
// Try to open an HDF5 named as the EPC file in the same folder (in case it would have been renamed)
replacedName = std::regex_replace(getUriSource(), std::regex("(.epc)$"), ".h5");
if (H5Fis_hdf5(replacedName.c_str()) <= 0) {
replacedName = std::regex_replace(getUriSource(), std::regex("(.epc)$"), ".hdf5");
if (H5Fis_hdf5(replacedName.c_str()) <= 0) {
throw invalid_argument("The HDF5 file " + fullName + " does not exist or is not a valid HDF5 file or is not accessible. Neither "
+ std::regex_replace(getUriSource(), std::regex("(.epc)$"), ".h5") + " nor " + std::regex_replace(getUriSource(), std::regex("(.epc)$"), ".hdf5"));
}
}
repository->addWarning("Could not found HDF5 file " + fullName + " but could found " + replacedName);
}

// Check the uuid
const string hdfUuid = readStringAttribute(".", "uuid");
if (getUuid() != hdfUuid) {
getRepository()->addWarning("The uuid \"" + hdfUuid + "\" attribute of the HDF5 file is not the same as the uuid \"" + getUuid() + "\" of the xml EpcExternalPart.");
}
hdfFile = H5Fopen(replacedName.c_str(),
openingMode == COMMON_NS::DataObjectRepository::openingMode::READ_ONLY ? H5F_ACC_RDONLY : H5F_ACC_RDWR,
H5P_DEFAULT);
if (hdfFile < 0) {
throw invalid_argument("HDF5 library recognizes the HDF5 file but can not open it : " + replacedName);
}
else {
throw invalid_argument("The HDF5 file " + fullName + " does not exist or is not a valid HDF5 file or is not accessible.");

// Check the uuid
const string hdfUuid = readStringAttribute(".", "uuid");
if (getUuid().size() == 36 && getUuid() != hdfUuid) {
getRepository()->addWarning("The uuid \"" + hdfUuid + "\" attribute of the HDF5 file is not the same as the uuid \"" + getUuid() + "\" of the XML EpcExternalPartReference.");
}
}
else if (openingMode == COMMON_NS::DataObjectRepository::openingMode::READ_WRITE) {
Expand Down

0 comments on commit 6c897ef

Please sign in to comment.