diff --git a/src/core/qgsdataitem.cpp b/src/core/qgsdataitem.cpp index 3279e4abcfe4..ea252b7445b0 100644 --- a/src/core/qgsdataitem.cpp +++ b/src/core/qgsdataitem.cpp @@ -775,10 +775,12 @@ QgsZipItem::~QgsZipItem() // internal function to scan a vsidir (zip or tar file) recursively // GDAL trunk has this since r24423 (05/16/12) - VSIReadDirRecursive() -// use a copy of the function internally for now +// use a copy of the function internally for now, +// but use char ** and CSLAddString, because CPLStringList was added in gdal-1.9 char **VSIReadDirRecursive1( const char *pszPath ) { - CPLStringList oFiles = NULL; + // CPLStringList oFiles = NULL; + char **papszOFiles = NULL; char **papszFiles1 = NULL; char **papszFiles2 = NULL; VSIStatBufL psStatBuf; @@ -805,7 +807,8 @@ char **VSIReadDirRecursive1( const char *pszPath ) if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 && VSI_ISREG( psStatBuf.st_mode ) ) { - oFiles.AddString( papszFiles1[i] ); + // oFiles.AddString( papszFiles1[i] ); + papszOFiles = CSLAddString( papszOFiles, papszFiles1[i] ); } else if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 && VSI_ISDIR( psStatBuf.st_mode ) ) @@ -814,7 +817,8 @@ char **VSIReadDirRecursive1( const char *pszPath ) osTemp2.clear(); osTemp2.append( papszFiles1[i] ); osTemp2.append( "/" ); - oFiles.AddString( osTemp2.c_str() ); + // oFiles.AddString( osTemp2.c_str() ); + papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() ); // recursively add files inside directory papszFiles2 = VSIReadDirRecursive1( osTemp1.c_str() ); @@ -827,7 +831,8 @@ char **VSIReadDirRecursive1( const char *pszPath ) osTemp2.append( papszFiles1[i] ); osTemp2.append( "/" ); osTemp2.append( papszFiles2[j] ); - oFiles.AddString( osTemp2.c_str() ); + // oFiles.AddString( osTemp2.c_str() ); + papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() ); } CSLDestroy( papszFiles2 ); } @@ -835,7 +840,8 @@ char **VSIReadDirRecursive1( const char *pszPath ) } CSLDestroy( papszFiles1 ); - return oFiles.StealList(); + // return oFiles.StealList(); + return papszOFiles; } QVector QgsZipItem::createChildren( ) diff --git a/tests/src/core/testziplayer.cpp b/tests/src/core/testziplayer.cpp index bfc232a9cae3..53bf40fd34a6 100644 --- a/tests/src/core/testziplayer.cpp +++ b/tests/src/core/testziplayer.cpp @@ -77,6 +77,8 @@ class TestZipLayer: public QObject void testGZipItemVectorTransparency(); void testZipItemRasterTransparency(); void testGZipItemRasterTransparency(); + //make sure items inside subfolders can be read + void testZipItemSubfolder(); }; @@ -215,6 +217,12 @@ void TestZipLayer::initTestCase() { QgsApplication::init(); QgsApplication::initQgis(); + + // output test environment + QgsApplication::showSettings(); + qDebug() << "GDAL version (build): " << GDAL_RELEASE_NAME; + qDebug() << "GDAL version (runtime): " << GDALVersionInfo( "RELEASE_NAME" ); + // save data dir mDataDir = QString( TEST_DATA_DIR ) + QDir::separator(); // Set up the QSettings environment @@ -370,5 +378,15 @@ void TestZipLayer::testGZipItemRasterTransparency() QVERIFY2(( myTransparency == myTarget ), QString( "Transparency is %1, should be %2" ).arg( myTransparency ).arg( myTarget ).toLocal8Bit().data() ); } +void TestZipLayer::testZipItemSubfolder() +{ + QSettings settings; + for ( int i = 2 ; i <= mMaxScanZipSetting ; i++ ) + { + settings.setValue( "/qgis/scanZipInBrowser", i ); + QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() ); + QVERIFY( testZipItem( mDataDir + "testzip.zip", "folder/folder2/landsat_b2.tif" ) ); + } +} QTEST_MAIN( TestZipLayer ) #include "moc_testziplayer.cxx" diff --git a/tests/testdata/testzip.zip b/tests/testdata/testzip.zip index 6f8572b120f7..01e956017966 100644 Binary files a/tests/testdata/testzip.zip and b/tests/testdata/testzip.zip differ