Skip to content
Permalink
Browse files

Merge pull request #141 from etiennesky/zip_fixes2

zip files: update VSIReadDirRecursive1() from VSIReadDirRecursive() in gdal trunk
  • Loading branch information
timlinux committed May 19, 2012
2 parents 1e7b9ed + b6997a0 commit 9dcee6b424f028abf38b59a1111801287e9e7c9e
Showing with 30 additions and 21 deletions.
  1. +30 −21 src/core/qgsdataitem.cpp
@@ -774,59 +774,68 @@ QgsZipItem::~QgsZipItem()
}

// internal function to scan a vsidir (zip or tar file) recursively
// hopefully this will make it to GDAL
// GDAL trunk has this since r24423 (05/16/12) - VSIReadDirRecursive()
// use a copy of the function internally for now
char **VSIReadDirRecursive1( const char *pszPath )
{
char **papszFiles = NULL;
CPLStringList oFiles = NULL;
char **papszFiles1 = NULL;
char **papszFiles2 = NULL;
VSIStatBufL psStatBuf;
char szTemp1[1096];
char szTemp2[1096];
CPLString osTemp1, osTemp2;
int i, j;
int nCount1, nCount2;

// get listing
papszFiles1 = VSIReadDir( pszPath );
if ( ! papszFiles1 )
return NULL;

// get files and directories inside listing
for ( int i = 0; i < CSLCount( papszFiles1 ); i++ )
nCount1 = CSLCount( papszFiles1 );
for ( i = 0; i < nCount1; i++ )
{
// build complete file name for stat
strcpy( szTemp1, pszPath );
strcat( szTemp1, ( char* )"/" ); // this might not be ok on windows
strcat( szTemp1, papszFiles1[i] );
osTemp1.clear();
osTemp1.append( pszPath );
osTemp1.append( "/" );
osTemp1.append( papszFiles1[i] );

// if is file, add it
if ( VSIStatL( szTemp1, &psStatBuf ) == 0 &&
if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
VSI_ISREG( psStatBuf.st_mode ) )
{
papszFiles = CSLAddString( papszFiles, papszFiles1[i] );
oFiles.AddString( papszFiles1[i] );
}
else if ( VSIStatL( szTemp1, &psStatBuf ) == 0 &&
else if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
VSI_ISDIR( psStatBuf.st_mode ) )
{
// add directory entry
strcpy( szTemp2, papszFiles1[i] );
strcat( szTemp2, ( char* )"/" ); // this might not be ok on windows
papszFiles = CSLAddString( papszFiles, szTemp2 );
osTemp2.clear();
osTemp2.append( papszFiles1[i] );
osTemp2.append( "/" );
oFiles.AddString( osTemp2.c_str() );

// recursively add files inside directory
papszFiles2 = VSIReadDirRecursive1( szTemp1 );
papszFiles2 = VSIReadDirRecursive1( osTemp1.c_str() );
if ( papszFiles2 )
{
for ( int j = 0; j < CSLCount( papszFiles2 ); j++ )
nCount2 = CSLCount( papszFiles2 );
for ( j = 0; j < nCount2; j++ )
{
strcpy( szTemp2, papszFiles1[i] );
strcat( szTemp2, ( char* )"/" ); // this might not be ok on windows
strcat( szTemp2, papszFiles2[j] );
papszFiles = CSLAddString( papszFiles, szTemp2 );
osTemp2.clear();
osTemp2.append( papszFiles1[i] );
osTemp2.append( "/" );
osTemp2.append( papszFiles2[j] );
oFiles.AddString( osTemp2.c_str() );
}
CSLDestroy( papszFiles2 );
}
}
}
CSLDestroy( papszFiles1 );

return papszFiles;
return oFiles.StealList();
}

QVector<QgsDataItem*> QgsZipItem::createChildren( )

1 comment on commit 9dcee6b

@etiennesky

This comment has been minimized.

Copy link
Contributor

@etiennesky etiennesky commented on 9dcee6b May 20, 2012

Tim,

I just noticed that CPLStringList is only in gdal 1.9, so it won't compile on gdal < 1.9 - many build bots will fail tonight. WIll prepare a quick fix for this using char ** instead of CPLStrinList, at the cost of small performance hit.

Please sign in to comment.
You can’t perform that action at this time.