Added traces and debug code to investigate truncated version.xml issues on some configurations

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@2790 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 9823f1f692feeb2ee90a9e2b7c6fbd0b338d8b8e
Former-commit-id: 6b4606063b08cc2e56a90761cf0fe9b301dfb0f2
This commit is contained in:
pouillot 2010-09-25 10:33:09 +00:00
parent a5df528271
commit 8b37ca77ce

View file

@ -31,12 +31,24 @@ static char* strip_destdir( char *filename, char const *destdir )
return &filename[ destdir_length ];
}
static int findIndex( void *versionHandle, const char* dataLocation, const char* userLocation, char* path, bool dataOnly )
// Uncomment to get debug traces in findIndex.
#define DEBUG_FINDINDEX
#ifdef DEBUG_FINDINDEX
#define trace printf
#else
#define trace
#endif
static int findIndex( void *versionHandle, const char* dataLocation,
const char* userLocation, char* path, bool dataOnly )
{
int nbIndices = GfParmGetEltNb( versionHandle, path ) + 1;
char *indices = (char*)malloc( sizeof(char) * nbIndices );
int curIndex;
trace("findIndex(h=%p, d=%s, u=%s, p=%s, dataonly=%d) : n=%d\n",
versionHandle, dataLocation, userLocation, path, dataOnly, nbIndices-1);
memset( indices, FALSE, nbIndices );
if( GfParmListSeekFirst( versionHandle, path ) == 0 )
@ -44,34 +56,41 @@ static int findIndex( void *versionHandle, const char* dataLocation, const char*
do
{
curIndex = atoi( GfParmListGetCurEltName( versionHandle, path ) );
trace(" Examining index %d : ", curIndex);
if( curIndex >= 0 && curIndex < nbIndices )
indices[ curIndex ] = TRUE;
if( strcmp( GfParmGetCurStr( versionHandle, path, "Data location", "" ), dataLocation ) == 0 &&
( dataOnly || strcmp( GfParmGetCurStr( versionHandle, path, "Local location", "" ), userLocation ) == 0 ) )
{
trace("yes.\n");
free( indices );
return curIndex;
}
trace("no.\n");
} while( GfParmListSeekNext( versionHandle, path ) == 0 );
}
curIndex = 0;
while( indices[ curIndex ] )
++curIndex;
trace(" New = %d.\n", curIndex);
free( indices );
return curIndex;
}
static int process( const char* xmlVersion, char* dataLocation, char* userLocation, char const* destdir )
static int process( const char* versionFile, char* dataLocation, char* userLocation, char const* destdir )
{
void *versionHandle;
void *xmlHandle;
int index;
char *path;
char *pathStart = strdup( "versions" );
char* actualDataLoc;
int majorVer, minorVer;
xmlHandle = GfParmReadFile( dataLocation, GFPARM_RMODE_STD );
if( !xmlHandle )
@ -80,21 +99,25 @@ static int process( const char* xmlVersion, char* dataLocation, char* userLocati
return 1;
}
versionHandle = GfParmReadFile( xmlVersion, GFPARM_RMODE_CREAT );
versionHandle = GfParmReadFile( versionFile, GFPARM_RMODE_CREAT );
if( !versionHandle )
{
fprintf( stderr, "xmlversion: Cannot open or create xml-file \"%s\".\n", xmlVersion );
fprintf( stderr, "xmlversion: Cannot open or create xml-file \"%s\".\n", versionFile );
return 1;
}
index = findIndex( versionHandle, dataLocation, userLocation, pathStart, false );
actualDataLoc = strip_destdir( dataLocation, destdir );
majorVer = GfParmGetMajorVersion( xmlHandle );
minorVer = GfParmGetMinorVersion( xmlHandle );
path = (char*)malloc( sizeof(char) * 31 );
snprintf( path, 30, "versions/%d", index );
GfParmSetStr( versionHandle, path, "Data location", strip_destdir( dataLocation, destdir ) );
GfParmSetStr( versionHandle, path, "Data location", actualDataLoc);
GfParmSetStr( versionHandle, path, "Local location", userLocation );
GfParmSetNum( versionHandle, path, "Major version", NULL, (tdble)GfParmGetMajorVersion( xmlHandle ) );
GfParmSetNum( versionHandle, path, "Minor version", NULL, (tdble)GfParmGetMinorVersion( xmlHandle ) );
GfParmSetNum( versionHandle, path, "Major version", NULL, (tdble)majorVer);
GfParmSetNum( versionHandle, path, "Minor version", NULL, (tdble)minorVer);
free( pathStart );
free( path );
@ -104,31 +127,35 @@ static int process( const char* xmlVersion, char* dataLocation, char* userLocati
GfParmReleaseHandle( versionHandle );
GfParmReleaseHandle( xmlHandle );
GfTrace("xmlVersion: updated \"%s\".\n", xmlVersion);
fprintf(stderr, "xmlversion: updated %s (file #%d %s (version %d.%d) => %s).\n",
versionFile, index, actualDataLoc, majorVer, minorVer, userLocation);
return 0;
}
static int add_directory( const char* xmlVersion, char* directoryName, char const* destdir )
static int add_directory( const char* versionFile, char* directoryName, char const* destdir )
{
void *versionHandle;
char *path;
char *pathStart = strdup( "directories" );
int index;
char* actualDataLoc;
versionHandle = GfParmReadFile( xmlVersion, GFPARM_RMODE_STD );
versionHandle = GfParmReadFile( versionFile, GFPARM_RMODE_STD );
if( !versionHandle )
{
GfParmReleaseHandle( versionHandle );
fprintf( stderr, "xmlversion: Cannot open or create xml-file \"%s\".\n", xmlVersion );
fprintf( stderr, "xmlversion: Cannot open or create xml-file \"%s\".\n", versionFile );
return 1;
}
index = findIndex( versionHandle, directoryName, "", pathStart, true );
actualDataLoc = strip_destdir( directoryName, destdir );
path = (char*)malloc( sizeof(char) * 31 );
snprintf( path, 30, "directories/%d", index );
GfParmSetStr( versionHandle, path, "Data location", strip_destdir( directoryName, destdir ) );
GfParmSetStr( versionHandle, path, "Data location", actualDataLoc);
free( pathStart );
free( path );
@ -137,14 +164,14 @@ static int add_directory( const char* xmlVersion, char* directoryName, char cons
GfParmReleaseHandle( versionHandle );
GfTrace("xmlversion: updated \"%s\".\n", xmlVersion);
fprintf(stderr, "xmlversion: updated %s (directory %s).\n", versionFile, actualDataLoc);
return 0;
}
int main( int argc, char **argv )
{
char *xmlversion;
char *versionfile;
char *dataLocation;
char *userLocation;
char const *destdir;
@ -169,21 +196,22 @@ int main( int argc, char **argv )
if( argc > 4 )
fprintf( stderr, "Warning: too many arguments in xmlversion. Ignoring extra arguments\n" );
xmlversion = strdup( argv[1] );
versionfile = strdup( argv[1] );
dataLocation = strdup( argv[2] );
userLocation = strdup( argv[3] );
destdir = getenv( "DESTDIR" );
fprintf(stderr, "xmlversion: DESTDIR=%s\n", destdir ? destdir : "<undefined>");
if( strcmp( xmlversion, "-d" ) == 0 )
if( strcmp( versionfile, "-d" ) == 0 )
ret = add_directory( dataLocation, userLocation, destdir );
else if( strcmp( dataLocation, "-d" ) == 0 )
ret = add_directory( xmlversion, userLocation, destdir );
ret = add_directory( versionfile, userLocation, destdir );
else if( strcmp( userLocation, "-d" ) == 0 )
ret = add_directory( xmlversion, dataLocation, destdir );
ret = add_directory( versionfile, dataLocation, destdir );
else
ret = process( xmlversion, dataLocation, userLocation, destdir );
ret = process( versionfile, dataLocation, userLocation, destdir );
free( xmlversion );
free( versionfile );
free( dataLocation );
free( userLocation );