hdf5-specific changes for hdf5grp.c

This commit is contained in:
Ed Hartnett 2018-11-12 13:43:43 -07:00
parent 902ee64ff0
commit 766f1d0195

View File

@ -91,7 +91,7 @@ NC4_def_grp(int parent_ncid, const char *name, int *new_ncid)
int int
NC4_rename_grp(int grpid, const char *name) NC4_rename_grp(int grpid, const char *name)
{ {
NC_GRP_INFO_T *grp, *parent; NC_GRP_INFO_T *grp;
NC_HDF5_GRP_INFO_T *hdf5_grp; NC_HDF5_GRP_INFO_T *hdf5_grp;
NC_FILE_INFO_T *h5; NC_FILE_INFO_T *h5;
char norm_name[NC_MAX_NAME + 1]; char norm_name[NC_MAX_NAME + 1];
@ -113,7 +113,6 @@ NC4_rename_grp(int grpid, const char *name)
/* Do not allow renaming the root group */ /* Do not allow renaming the root group */
if (grp->parent == NULL) if (grp->parent == NULL)
return NC_EBADGRPID; return NC_EBADGRPID;
parent = grp->parent;
/* Check and normalize the name. */ /* Check and normalize the name. */
if ((retval = nc4_check_name(name, norm_name))) if ((retval = nc4_check_name(name, norm_name)))
@ -121,7 +120,7 @@ NC4_rename_grp(int grpid, const char *name)
/* Check that this name is not in use as a var, grp, or type in the /* Check that this name is not in use as a var, grp, or type in the
* parent group (i.e. the group that grp is in). */ * parent group (i.e. the group that grp is in). */
if ((retval = nc4_check_dup_name(parent, norm_name))) if ((retval = nc4_check_dup_name(grp->parent, norm_name)))
return retval; return retval;
/* If it's not in define mode, switch to define mode. */ /* If it's not in define mode, switch to define mode. */
@ -130,26 +129,27 @@ NC4_rename_grp(int grpid, const char *name)
return retval; return retval;
/* Rename the group, if it exists in the file */ /* Rename the group, if it exists in the file */
if (grp->hdf_grpid) if (hdf5_grp->hdf_grpid)
{ {
NC_HDF5_GRP_INFO_T *parent_hdf5_grp; NC_HDF5_GRP_INFO_T *parent_hdf5_grp;
parent_hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->parent->format_grp_info; parent_hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->parent->format_grp_info;
/* Close the group */ /* Close the group */
if (H5Gclose(grp->hdf_grpid) < 0) if (H5Gclose(hdf5_grp->hdf_grpid) < 0)
return NC_EHDFERR; return NC_EHDFERR;
hdf5_grp->hdf_grpid = 0; hdf5_grp->hdf_grpid = 0;
grp->hdf_grpid = 0; grp->hdf_grpid = 0;
/* Attempt to rename & re-open the group, if the parent group is open */ /* Attempt to rename & re-open the group, if the parent group is open */
if (grp->parent->hdf_grpid) if (parent_hdf5_grp->hdf_grpid)
{ {
/* Rename the group */ /* Rename the group */
if (H5Gmove(parent->hdf_grpid, grp->hdr.name, name) < 0) if (H5Gmove(parent_hdf5_grp->hdf_grpid, grp->hdr.name, name) < 0)
return NC_EHDFERR; return NC_EHDFERR;
/* Reopen the group, with the new name */ /* Reopen the group, with the new name */
if ((hdf5_grp->hdf_grpid = H5Gopen2(parent->hdf_grpid, name, H5P_DEFAULT)) < 0) if ((hdf5_grp->hdf_grpid = H5Gopen2(parent_hdf5_grp->hdf_grpid, name,
H5P_DEFAULT)) < 0)
return NC_EHDFERR; return NC_EHDFERR;
grp->hdf_grpid = hdf5_grp->hdf_grpid; grp->hdf_grpid = hdf5_grp->hdf_grpid;
} }
@ -162,7 +162,7 @@ NC4_rename_grp(int grpid, const char *name)
return NC_ENOMEM; return NC_ENOMEM;
grp->hdr.hashkey = NC_hashmapkey(grp->hdr.name,strlen(grp->hdr.name)); /* Fix hash key */ grp->hdr.hashkey = NC_hashmapkey(grp->hdr.name,strlen(grp->hdr.name)); /* Fix hash key */
if(!ncindexrebuild(parent->children)) if(!ncindexrebuild(grp->parent->children))
return NC_EINTERNAL; return NC_EINTERNAL;
return NC_NOERR; return NC_NOERR;