Skip to content

Commit

Permalink
Enable automatic creation intermediate groups when making soft/hard/e…
Browse files Browse the repository at this point in the history
…xternal links
  • Loading branch information
DavidAce committed Oct 1, 2022
1 parent 57b0e91 commit e681348
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions include/h5pp/details/h5ppHdf5.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,11 +873,11 @@ namespace h5pp::hdf5 {
}

h5pp::logger::log->trace("Creating soft link [{}] --> [{}]", targetLinkPath, softLinkPath);
herr_t retval = H5Lcreate_soft(util::safe_str(targetLinkPath).c_str(),
loc,
util::safe_str(softLinkPath).c_str(),
plists.linkCreate,
plists.linkAccess);
hid::h5p lcpl = H5Pcopy(plists.linkCreate);
if(H5Pset_create_intermediate_group(lcpl, 1) < 0) // Set to create intermediate groups
throw h5pp::runtime_error("H5Pset_create_intermediate_group failed");
herr_t retval =
H5Lcreate_soft(util::safe_str(targetLinkPath).c_str(), loc, util::safe_str(softLinkPath).c_str(), lcpl, plists.linkAccess);
if(retval < 0) throw h5pp::runtime_error("Failed to create soft link [{}] ", targetLinkPath);
}

Expand All @@ -895,11 +895,14 @@ namespace h5pp::hdf5 {
throw h5pp::runtime_error("Tried to create a hard link to a path that does not exist [{}]", targetLinkPath);
}
h5pp::logger::log->trace("Creating hard link [{}] --> [{}]", targetLinkPath, hardLinkPath);
hid::h5p lcpl = H5Pcopy(plists.linkCreate);
if(H5Pset_create_intermediate_group(lcpl, 1) < 0) // Set to create intermediate groups
throw h5pp::runtime_error("H5Pset_create_intermediate_group failed");
herr_t retval = H5Lcreate_hard(targetLinkLoc,
util::safe_str(targetLinkPath).c_str(),
hardLinkLoc,
util::safe_str(hardLinkPath).c_str(),
plists.linkCreate,
lcpl,
plists.linkAccess);
if(retval < 0) throw h5pp::runtime_error("Failed to create hard link [{}] -> [{}] ", targetLinkPath, hardLinkPath);
}
Expand All @@ -914,12 +917,14 @@ namespace h5pp::hdf5 {
"Template function [h5pp::hdf5::createExternalLink(const h5x & loc, ...)] requires type h5x to be: "
"[h5pp::hid::h5f], [h5pp::hid::h5g], [h5pp::hid::h5o] or [hid_t]");
h5pp::logger::log->trace("Creating external link [{}] from file [{}] : [{}]", softLinkPath, targetFilePath, targetLinkPath);

hid::h5p lcpl = H5Pcopy(plists.linkCreate);
if(H5Pset_create_intermediate_group(lcpl, 1) < 0) // Set to create intermediate groups
throw h5pp::runtime_error("H5Pset_create_intermediate_group failed");
herr_t retval = H5Lcreate_external(util::safe_str(targetFilePath).c_str(),
util::safe_str(targetLinkPath).c_str(),
loc,
util::safe_str(softLinkPath).c_str(),
plists.linkCreate,
lcpl,
plists.linkAccess);

if(retval < 0) throw h5pp::runtime_error("Failed to create external link [{}] --> [{}]", targetLinkPath, softLinkPath);
Expand Down

0 comments on commit e681348

Please sign in to comment.