diff --git a/libnczarr/zformat2.c b/libnczarr/zformat2.c index 158be08e95..e27148031c 100644 --- a/libnczarr/zformat2.c +++ b/libnczarr/zformat2.c @@ -734,11 +734,13 @@ ZF2_upload_grp(NC_FILE_INFO_T* file, NC_GRP_INFO_T* grp, struct ZOBJ* zobj) if((stat=NCZ_uploadjson(zinfo->map,key,zobj->jobj))) goto done; nullfree(key); key = NULL; - /* build ZATTRS path */ - if((stat = nczm_concat(fullpath,Z2ATTRS,&key))) goto done; - /* Write to map */ - if((stat=NCZ_uploadjson(zinfo->map,key,zobj->jatts))) goto done; - nullfree(key); key = NULL; + if(zobj->jatts != NULL) { + /* build ZATTRS path */ + if((stat = nczm_concat(fullpath,Z2ATTRS,&key))) goto done; + /* Write to map */ + if((stat=NCZ_uploadjson(zinfo->map,key,zobj->jatts))) goto done; + nullfree(key); key = NULL; + } done: nullfree(fullpath); @@ -763,7 +765,7 @@ ZF2_upload_var(NC_FILE_INFO_T* file, NC_VAR_INFO_T* var, struct ZOBJ* zobj) if((stat=NCZ_uploadjson(zinfo->map,key,zobj->jobj))) goto done; nullfree(key); key = NULL; - if(zobj->jatts) { + if(zobj->jatts != NULL) { /* build ZATTRS path */ if((stat = nczm_concat(fullpath,Z2ATTRS,&key))) goto done; /* Write to map */ @@ -1271,31 +1273,44 @@ ZF2_searchobjects(NC_FILE_INFO_T* file, NC_GRP_INFO_T* grp, NClist* varnames, NC size_t i; NCZ_FILE_INFO_T* zfile = (NCZ_FILE_INFO_T*)file->format_file_info; char* grpkey = NULL; + char* subgrpkey = NULL; char* varkey = NULL; char* zarray = NULL; + char* zgroup = NULL; NClist* matches = nclistnew(); /* Compute the key for the grp */ if((stat = NCZ_grpkey(grp,&grpkey))) goto done; - /* Get the map and search group */ - if((stat = nczmap_list(zfile->map,grpkey,matches))) goto done; + if((stat = nczmap_list(zfile->map,grpkey,matches))) goto done; /* Shallow listing */ + /* Search grp for group-level .zxxx and for var-level .zxxx*/ for(i=0;imap,zarray)) == NC_NOERR) + if((stat = nczmap_exists(zfile->map,zarray)) == NC_NOERR) { nclistpush(varnames,strdup(name)); + } else { + /* See if name is a group by testing for name/.zgroup exists */ + if((stat = nczm_concat(grpkey,name,&subgrpkey))) goto done; + if((stat = nczm_concat(varkey,Z2GROUP,&zgroup))) goto done; + if((stat = nczmap_exists(zfile->map,zgroup)) == NC_NOERR) + nclistpush(subgrpnames,strdup(name)); + } stat = NC_NOERR; nullfree(varkey); varkey = NULL; nullfree(zarray); zarray = NULL; + nullfree(subgrpkey); subgrpkey = NULL; + nullfree(zgroup); zgroup = NULL; } done: nullfree(grpkey); nullfree(varkey); nullfree(zarray); + nullfree(zgroup); + nullfree(subgrpkey); nclistfreeall(matches); return stat; } diff --git a/libnczarr/zmap.h b/libnczarr/zmap.h index 064b977215..5c6acd82a9 100644 --- a/libnczarr/zmap.h +++ b/libnczarr/zmap.h @@ -62,10 +62,10 @@ implementing the key/object model. The list function takes a prefix path which has a key syntax (see above). The set of legal keys is the set of keys such that the key references a content-bearing object -- e.g. /x/y/.zarray or -/.zgroup. Essentially this is the set of keys pointing to the leaf -objects of the tree of keys constituting a dataset. This set -potentially limits the set of keys that need to be examined during -search. +/.zgroup or /g/.zgroup. Essentially this is the set of keys pointing +to the leaf objects of the tree of keys constituting a dataset. +This set potentially limits the set of keys that need to be examined +during search. The list function has two primary purposes: 1. Support reading of pure zarr datasets (because they do not explicitly track their contents). diff --git a/libnczarr/zmap_file.c b/libnczarr/zmap_file.c index ada1db6305..a2a40ec373 100644 --- a/libnczarr/zmap_file.c +++ b/libnczarr/zmap_file.c @@ -463,7 +463,8 @@ zfileclose(NCZMAP* map, int delete) } /* -Return a list of simple names immediately "below" a specified prefix key. +Return a list of simple names immediately "below" a specified prefix key +(i.e. shallow listing). In theory, the returned list should be sorted in lexical order, but it possible that it is not. The prefix key is not included. @@ -962,7 +963,7 @@ platformdircontent(const char* canonpath, NClist* contents) default: goto done; } - /* We need to process the path to make it work with FindFirstFile */ + /* We need to process the path to make it work with Windows FindFirstFile */ len = strlen(canonpath); /* Need to terminate path with '/''*' */ ffpath = (char*)malloc(len+2+1); diff --git a/libnczarr/zsync.c b/libnczarr/zsync.c index 3f4aae2020..b13edd85fc 100644 --- a/libnczarr/zsync.c +++ b/libnczarr/zsync.c @@ -405,7 +405,7 @@ ncz_decode_file(NC_FILE_INFO_T* file) root = file->root_grp; if((stat = NCZF_download_grp(file, root, &zobj))) goto done; - /* Decode the group metadata to get superblock */ + /* Decode the group metadata to get only the superblock */ if((stat = NCZF_decode_group(file,root,&zobj,NULL,(NCjson**)&jsuper))) goto done; if(jsuper != NULL) {