From b75540244fb313f179fe11c587e5e008677e6762 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 3 Jun 2008 19:17:27 -0500 Subject: [svn-r15133] Description: Fixed bug in h5ls that prevented relative group listings (like "h5ls foo.h5/bar") from working correctly. Tested on: FreeBSD/32 6.2 (duty) in debug mode FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Mac OS X/32 10.5.3 (amazon) in debug mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode --- MANIFEST | 1 + release_docs/RELEASE.txt | 2 ++ tools/h5ls/h5ls.c | 35 +++++++++++++++++++++++++---------- tools/h5ls/testh5ls.sh | 1 + tools/lib/h5trav.c | 45 ++++++++++++++------------------------------- tools/testfiles/tgroup-3.ls | 5 +++++ 6 files changed, 48 insertions(+), 41 deletions(-) create mode 100644 tools/testfiles/tgroup-3.ls diff --git a/MANIFEST b/MANIFEST index 1af3eb8..1be4386 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1293,6 +1293,7 @@ ./tools/testfiles/tdset-1.ls ./tools/testfiles/tgroup-1.ls ./tools/testfiles/tgroup-2.ls +./tools/testfiles/tgroup-3.ls ./tools/testfiles/tgroup.ls ./tools/testfiles/thlink-1.ls ./tools/testfiles/tloop-1.ls diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 1b2d2cf..43c661c 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -108,6 +108,8 @@ Bug Fixes since HDF5-1.8.0 release Tools ----- + - Fixed bug in h5ls that prevented relative group listings (like + "h5ls foo.h5/bar") from working correctly (QAK - 2008/06/03) - Fixed bug in h5diff that prevented datasets & attributes with variable-length string elements from comparing correctly. (QAK - 2008/02/28) diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index 80b45d8..6f07050 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -33,8 +33,8 @@ /* Struct to pass through to visitors */ typedef struct { - hid_t fid; /* File ID */ const char *fname; /* Filename */ + hid_t gid; /* Group ID */ }iter_t; /* Command-line switches */ @@ -1687,7 +1687,7 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void /* Open the object. Not all objects can be opened. If this is the case * then return right away. */ - if(obj_type >= 0 && (obj = H5Oopen(iter->fid, name, H5P_DEFAULT)) < 0) { + if(obj_type >= 0 && (obj = H5Oopen(iter->gid, name, H5P_DEFAULT)) < 0) { printf(" *ERROR*\n"); goto done; } /* end if */ @@ -1779,7 +1779,7 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) if((buf = HDmalloc(linfo->u.val_size)) == NULL) goto done; - if(H5Lget_val(iter->fid, name, buf, linfo->u.val_size, H5P_DEFAULT) < 0) { + if(H5Lget_val(iter->gid, name, buf, linfo->u.val_size, H5P_DEFAULT) < 0) { HDfree(buf); goto done; } /* end if */ @@ -1796,7 +1796,7 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) if((buf = HDmalloc(linfo->u.val_size)) == NULL) goto done; - if(H5Lget_val(iter->fid, name, buf, linfo->u.val_size, H5P_DEFAULT) < 0) { + if(H5Lget_val(iter->gid, name, buf, linfo->u.val_size, H5P_DEFAULT) < 0) { HDfree(buf); goto done; } /* end if */ @@ -2164,7 +2164,7 @@ main(int argc, const char *argv[]) /* Shorten the file name; lengthen the object name */ x = oname; - oname = strrchr(fname, '/'); + oname = HDstrrchr(fname, '/'); if(x) *x = '/'; if(!oname) @@ -2185,7 +2185,7 @@ main(int argc, const char *argv[]) /* Remember the file information for later */ iter.fname = fname; - iter.fid = file; + iter.gid = -1; /* Check for root group as object name */ if(HDstrcmp(oname, root_name)) { @@ -2209,13 +2209,28 @@ main(int argc, const char *argv[]) } /* end if */ /* Check for group iteration */ - if(H5O_TYPE_GROUP == oi.type && !grp_literal_g) + if(H5O_TYPE_GROUP == oi.type && !grp_literal_g) { + /* Get ID for group */ + if((iter.gid = H5Gopen2(file, oname, H5P_DEFAULT)) < 0) { + fprintf(stderr, "%s: unable to open '%s' as group\n", fname, oname); + continue; + } /* end if */ + /* Specified name is a group. List the complete contents of the group. */ h5trav_visit(file, oname, display_root_g, recursive_g, list_obj, list_lnk, &iter); - else + + /* Close group */ + H5Gclose(iter.gid); + } /* end if */ + else { + /* Use file ID for root group ID */ + iter.gid = file; + /* Specified name is a non-group object -- list that object */ list_obj(oname, &oi, NULL, &iter); - } else + } /* end else */ + } /* end if */ + else /* Specified name is not for object -- list that link */ list_lnk(oname, &li, &iter); H5Fclose(file); @@ -2223,5 +2238,5 @@ main(int argc, const char *argv[]) } /* end while */ leave(0); -} +} /* end main() */ diff --git a/tools/h5ls/testh5ls.sh b/tools/h5ls/testh5ls.sh index cef5730..6383709 100755 --- a/tools/h5ls/testh5ls.sh +++ b/tools/h5ls/testh5ls.sh @@ -113,6 +113,7 @@ TOOLTEST help-3.ls 0 -w80 -? TOOLTEST tall-1.ls 0 -w80 tall.h5 TOOLTEST tall-2.ls 0 -w80 -r -d tall.h5 TOOLTEST tgroup.ls 0 -w80 tgroup.h5 +TOOLTEST tgroup-3.ls 0 -w80 tgroup.h5/g1 # test for displaying groups # The following combination of arguments is expected to return an error message diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index 14ced60..0ed6a30 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -39,6 +39,7 @@ typedef struct { typedef struct { trav_addr_t *seen; /* List of addresses seen already */ const trav_visitor_t *visitor; /* Information for visiting each link/object */ + hbool_t is_absolute; /* Whether the traversal has absolute paths */ } trav_ud_traverse_t; typedef struct { @@ -139,13 +140,19 @@ traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo, void *_udata) { trav_ud_traverse_t *udata = (trav_ud_traverse_t *)_udata; /* User data */ - char *full_name; + char *new_name = NULL; + const char *full_name; const char *already_visited = NULL; /* Whether the link/object was already visited */ /* Create the full path name for the link */ - full_name = HDmalloc(HDstrlen(path) + 2); - *full_name = '/'; - HDstrcpy(full_name + 1, path); + if(udata->is_absolute) { + new_name = HDmalloc(HDstrlen(path) + 2); + *new_name = '/'; + HDstrcpy(new_name + 1, path); + full_name = new_name; + } /* end if */ + else + full_name = path; /* Perform the correct action for different types of links */ if(linfo->type == H5L_TYPE_HARD) { @@ -172,7 +179,8 @@ traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo, (*udata->visitor->visit_lnk)(full_name, linfo, udata->visitor->udata); } /* end else */ - HDfree(full_name); + if(new_name) + HDfree(new_name); return(H5_ITER_CONT); } /* end traverse_cb() */ @@ -222,6 +230,7 @@ traverse(hid_t file_id, const char *grp_name, hbool_t visit_start, /* Set up user data structure */ udata.seen = &seen; udata.visitor = visitor; + udata.is_absolute = (*grp_name == '/'); /* Check for iteration of links vs. visiting all links recursively */ if(recurse) { @@ -582,32 +591,6 @@ h5trav_getindext(const char *name, const trav_table_t *table) } /*------------------------------------------------------------------------- - * Function: trav_table_search - * - * Purpose: Search in the table for OBJNO - * - * Return: index of object in table - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 4, 2002 - * - *------------------------------------------------------------------------- - */ - -static size_t -trav_table_search(const trav_table_t *table, haddr_t objno) -{ - size_t i; - - for(i = 0; i < table->nobjs; i++) - if(table->objs[i].objno == objno) - return(i); - return(i); -} - - -/*------------------------------------------------------------------------- * Function: trav_table_add * * Purpose: Add OBJNO, NAME and TYPE of object to table diff --git a/tools/testfiles/tgroup-3.ls b/tools/testfiles/tgroup-3.ls new file mode 100644 index 0000000..cfb479a --- /dev/null +++ b/tools/testfiles/tgroup-3.ls @@ -0,0 +1,5 @@ +############################# + output for 'h5ls -w80 tgroup.h5/g1' +############################# +g1.1 Group +g1.2 Group -- cgit v0.12