Skip to content

Commit 9dcee6b

Browse files
committed
Merge pull request #141 from etiennesky/zip_fixes2
zip files: update VSIReadDirRecursive1() from VSIReadDirRecursive() in gdal trunk
2 parents 1e7b9ed + b6997a0 commit 9dcee6b

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

src/core/qgsdataitem.cpp

+30-21
Original file line numberDiff line numberDiff line change
@@ -774,59 +774,68 @@ QgsZipItem::~QgsZipItem()
774774
}
775775

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

787789
// get listing
788790
papszFiles1 = VSIReadDir( pszPath );
789791
if ( ! papszFiles1 )
790792
return NULL;
791793

792794
// get files and directories inside listing
793-
for ( int i = 0; i < CSLCount( papszFiles1 ); i++ )
795+
nCount1 = CSLCount( papszFiles1 );
796+
for ( i = 0; i < nCount1; i++ )
794797
{
795798
// build complete file name for stat
796-
strcpy( szTemp1, pszPath );
797-
strcat( szTemp1, ( char* )"/" ); // this might not be ok on windows
798-
strcat( szTemp1, papszFiles1[i] );
799+
osTemp1.clear();
800+
osTemp1.append( pszPath );
801+
osTemp1.append( "/" );
802+
osTemp1.append( papszFiles1[i] );
803+
799804
// if is file, add it
800-
if ( VSIStatL( szTemp1, &psStatBuf ) == 0 &&
805+
if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
801806
VSI_ISREG( psStatBuf.st_mode ) )
802807
{
803-
papszFiles = CSLAddString( papszFiles, papszFiles1[i] );
808+
oFiles.AddString( papszFiles1[i] );
804809
}
805-
else if ( VSIStatL( szTemp1, &psStatBuf ) == 0 &&
810+
else if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
806811
VSI_ISDIR( psStatBuf.st_mode ) )
807812
{
808813
// add directory entry
809-
strcpy( szTemp2, papszFiles1[i] );
810-
strcat( szTemp2, ( char* )"/" ); // this might not be ok on windows
811-
papszFiles = CSLAddString( papszFiles, szTemp2 );
814+
osTemp2.clear();
815+
osTemp2.append( papszFiles1[i] );
816+
osTemp2.append( "/" );
817+
oFiles.AddString( osTemp2.c_str() );
818+
812819
// recursively add files inside directory
813-
papszFiles2 = VSIReadDirRecursive1( szTemp1 );
820+
papszFiles2 = VSIReadDirRecursive1( osTemp1.c_str() );
814821
if ( papszFiles2 )
815822
{
816-
for ( int j = 0; j < CSLCount( papszFiles2 ); j++ )
823+
nCount2 = CSLCount( papszFiles2 );
824+
for ( j = 0; j < nCount2; j++ )
817825
{
818-
strcpy( szTemp2, papszFiles1[i] );
819-
strcat( szTemp2, ( char* )"/" ); // this might not be ok on windows
820-
strcat( szTemp2, papszFiles2[j] );
821-
papszFiles = CSLAddString( papszFiles, szTemp2 );
826+
osTemp2.clear();
827+
osTemp2.append( papszFiles1[i] );
828+
osTemp2.append( "/" );
829+
osTemp2.append( papszFiles2[j] );
830+
oFiles.AddString( osTemp2.c_str() );
822831
}
823832
CSLDestroy( papszFiles2 );
824833
}
825834
}
826835
}
827836
CSLDestroy( papszFiles1 );
828837

829-
return papszFiles;
838+
return oFiles.StealList();
830839
}
831840

832841
QVector<QgsDataItem*> QgsZipItem::createChildren( )

0 commit comments

Comments
 (0)