[svn-r7971] Purpose:

h5repack bug

Description:
changed the copy hardlinks algorithm
added more tests

Solution:

Platforms tested:
linux
solaris
IRIX


Misc. update:
This commit is contained in:
Pedro Vicente Nunes 2003-12-18 15:25:11 -05:00
parent 5b518c102d
commit 5658d88327
5 changed files with 124 additions and 44 deletions

View File

@ -37,9 +37,9 @@
int check_objects(const char* fname,
pack_opt_t *options)
{
hid_t fid;
int nobjects, i;
trav_info_t *info=NULL;
hid_t fid;
int i;
trav_table_t *travt=NULL;
/*-------------------------------------------------------------------------
* open the file
@ -58,29 +58,17 @@ int check_objects(const char* fname,
} H5E_END_TRY;
/*-------------------------------------------------------------------------
* get the number of objects in the file
*-------------------------------------------------------------------------
*/
if ((nobjects = h5trav_getinfo(fid, NULL ))<0) {
printf("h5repack: <%s>: Could not obtain object list\n", fname );
return -1;
}
/*-------------------------------------------------------------------------
* get the list of objects in the file
*-------------------------------------------------------------------------
*/
if ((info = (trav_info_t*) malloc( nobjects * sizeof(trav_info_t)))==NULL){
printf("h5repack: <%s>: Could not allocate object list\n", fname );
return -1;
}
if (h5trav_getinfo(fid, info )<0) {
printf("h5repack: <%s>: Could not obtain object list\n", fname );
return -1;
}
/* init table */
trav_table_init(&travt);
/* get the list of objects in the file */
if (h5trav_gettable(fid,travt)<0)
goto out;
/*-------------------------------------------------------------------------
* compare with user supplied list
@ -92,29 +80,32 @@ int check_objects(const char* fname,
for ( i = 0; i < options->op_tbl->nelems; i++)
{
char* obj_name=options->op_tbl->objs[i].path;
char* name=options->op_tbl->objs[i].path;
if (options->verbose)
printf(PFORMAT1,"","",obj_name);
printf(PFORMAT1,"","",name);
/* the input object names are present in the file and are valid */
if (h5trav_getindex(obj_name,nobjects,info)<0)
if (h5trav_getindext(name,travt)<0)
{
printf("\nError: Could not find <%s> in file <%s>. Exiting...\n",
obj_name,fname);
H5Fclose(fid);
h5trav_freeinfo(info,nobjects);
exit(1);
name,fname);
goto out;
}
if (options->verbose)
printf("...Found\n");
}
/*-------------------------------------------------------------------------
* free
* close
*-------------------------------------------------------------------------
*/
H5Fclose(fid);
h5trav_freeinfo(info,nobjects);
trav_table_free(travt);
return 0;
out:
H5Fclose(fid);
trav_table_free(travt);
return -1;
}

View File

@ -336,7 +336,6 @@ int make_special_objects(hid_t loc_id)
hsize_t dims[1]={2};
int buf[2]= {1,2};
/*-------------------------------------------------------------------------
* create a dataset and some hard links to it
*-------------------------------------------------------------------------
@ -351,25 +350,41 @@ int make_special_objects(hid_t loc_id)
if (H5Glink(loc_id, H5G_LINK_HARD, "dset", "link3 to dset")<0)
return -1;
/*-------------------------------------------------------------------------
* create a group and some hard links to it
*-------------------------------------------------------------------------
*/
if ((group1_id = H5Gcreate(loc_id,"g1",0))<0)
return -1;
if ((group2_id = H5Gcreate(group1_id,"g2",0))<0)
return -1;
if ((group3_id = H5Gcreate(group2_id,"g3",0))<0)
return -1;
if (H5Glink(loc_id, H5G_LINK_HARD, "g1", "link1 to g1")<0)
return -1;
if (H5Glink(loc_id, H5G_LINK_HARD, "g1", "link2 to g1")<0)
return -1;
/*
H5Glink2(curr_loc_id, current_name, link_type, new_loc_id, new_name )
hid_t curr_loc_id
IN: The file or group identifier for the original object.
const char * current_name
IN: Name of the existing object if link is a hard link.
H5G_link_t link_type
IN: Link type. Possible values are H5G_LINK_HARD and H5G_LINK_SOFT.
hid_t new_loc_id
IN: The file or group identifier for the new link.
const char * new_name
IN: New name for the object.
*/
if (H5Glink2(loc_id, "g1", H5G_LINK_HARD, group2_id, "link1 to g1")<0)
return -1;
if (H5Glink2(group1_id, "g2", H5G_LINK_HARD, group3_id, "link1 to g2")<0)
return -1;
H5Gclose(group1_id);
H5Gclose(group2_id);
H5Gclose(group3_id);
return 0;

View File

@ -389,11 +389,12 @@ int traverse( hid_t loc_id,
if ( table->objs[j].displayed == 0 )
{
table->objs[j].displayed = 1;
trav_table_addlink(table,j,path);
}
else
{
#if defined (H5_TRAV_DEBUG)
printf("<%s> HARDLINK to <%s>\n", path, table->objs[j].name);
printf("<%s> HARDLINK\n", path);
#endif
trav_table_addlink(table,j,path);
}
@ -429,11 +430,12 @@ int traverse( hid_t loc_id,
if ( table->objs[j].displayed == 0 )
{
table->objs[j].displayed = 1;
trav_table_addlink(table,j,path);
}
else
{
#if defined (H5_TRAV_DEBUG)
printf("<%s> HARDLINK to <%s>\n", path, table->objs[j].name);
printf("<%s> HARDLINK\n", path);
#endif
trav_table_addlink(table,j,path);
} /* displayed==1 */
@ -585,10 +587,65 @@ void h5trav_printtable(trav_table_t *table)
{
for ( j=0; j<table->objs[i].nlinks; j++)
{
printf(" %-10s %s\n", " hardlink", table->objs[i].links[j] );
printf(" %-10s %s\n", " hardlink", table->objs[i].links[j].new_name );
}
}
}
}
/*-------------------------------------------------------------------------
* Function: h5trav_getindext
*
* Purpose: get index of NAME in list
*
* Return: index, -1 if not found
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: December 18, 2003
*
*-------------------------------------------------------------------------
*/
int h5trav_getindext(const char *name, trav_table_t *table)
{
char *pdest;
int result;
int i, j;
for ( i = 0; i < table->nobjs; i++)
{
if ( strcmp(name,table->objs[i].name)==0 )
return i;
pdest = strstr( table->objs[i].name, name );
result = (int)(pdest - table->objs[i].name);
/* found at position 1, meaning without '/' */
if( pdest != NULL && result==1 )
return i;
/* search also in the list of links */
if (table->objs[i].nlinks)
{
for ( j=0; j<table->objs[i].nlinks; j++)
{
if ( strcmp(name,table->objs[i].links[j].new_name)==0 )
return i;
pdest = strstr( table->objs[i].links[j].new_name, name );
result = (int)(pdest - table->objs[i].links[j].new_name);
/* found at position 1, meaning without '/' */
if( pdest != NULL && result==1 )
return i;
}
}
}
return -1;
}

View File

@ -78,7 +78,7 @@ typedef struct trav_table_t {
/*-------------------------------------------------------------------------
* "h5trav info" public functions
* public functions
*-------------------------------------------------------------------------
*/
@ -86,12 +86,23 @@ typedef struct trav_table_t {
extern "C" {
#endif
/*-------------------------------------------------------------------------
* "h5trav info" public functions
*-------------------------------------------------------------------------
*/
int h5trav_getinfo( hid_t file_id, trav_info_t *info );
int h5trav_getindex( const char *obj, int nobjs, trav_info_t *info );
void h5trav_freeinfo( trav_info_t *info, int nobjs );
void h5trav_printinfo(int nobjs, trav_info_t *info);
int h5trav_gettable(hid_t fid, trav_table_t *travt);
/*-------------------------------------------------------------------------
* "h5trav table" public functions
*-------------------------------------------------------------------------
*/
int h5trav_getindext(const char *obj,trav_table_t *travt);
int h5trav_gettable(hid_t fid, trav_table_t *travt);
void h5trav_printtable(trav_table_t *table);
#ifdef __cplusplus
}
@ -119,7 +130,6 @@ void trav_table_addflags(unsigned *flags,
H5G_obj_t type,
trav_table_t *table);
void h5trav_printtable(trav_table_t *table);
void trav_table_addlink(trav_table_t *table,
int j /* the object index */,

View File

@ -235,14 +235,21 @@ void trav_table_addlink(trav_table_t *table,
char *path )
{
int k;
/* store the link information */
/* already inserted */
if (strcmp(table->objs[j].name,path)==0)
return;
/* allocate space if necessary */
if (table->objs[j].nlinks == table->objs[j].sizelinks) {
table->objs[j].sizelinks += 2;
table->objs[j].links =
(trav_link_t*)HDrealloc(table->objs[j].links,
table->objs[j].sizelinks * sizeof(trav_link_t));
}
k = table->objs[j].nlinks++;
/* insert it */
k=table->objs[j].nlinks++;
table->objs[j].links[k].new_name = (char*)HDstrdup(path);
}