From 86243eb8fe0e43dfa02c050c89e8e44283240b38 Mon Sep 17 00:00:00 2001 From: Etienne Tourigny Date: Sat, 19 May 2012 22:31:43 -0300 Subject: [PATCH] fix zip file reading for gdal<1.9 and add test for folder-in-zip --- src/core/qgsdataitem.cpp | 18 ++++++++++++------ tests/src/core/testziplayer.cpp | 18 ++++++++++++++++++ tests/testdata/testzip.zip | Bin 30764 -> 31891 bytes 3 files changed, 30 insertions(+), 6 deletions(-) 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 6f8572b120f75efd4b6d59c24b5526649bb07a2f..01e9560179664bc86ca8d730b863f98d9ad0a640 100644 GIT binary patch delta 1332 zcmZ4UfpPLr#`*wnW)?065V)~%vjdm`CD<8c7}D}{Qc{cbLqj+jm^)l|_;&(vX$3a} zBg+eB1_m$zGC%~Vg@fTL(16m7*B2Bs0lB;k45A1F3i31aN{aQ;Q}eTm^Yg&QH3E&A zvy@G zPh}lS@d)rwGjuCw+Z!P+M7dD!4wAKVq+@U8Hjji`Jp~n=_xVDV{oYvcGkboZ@fM8LO@?`=fie z*`rnK`k!UYlZOuA4Z%&%tRi#$;Il1Q}rbMjjucY07?w^CEfea)DpAA2>O~(sa$O>>tmU zXSBZ4l@+d^6c_ICSi{XXIeO9cKLQebHtUUHAb6MvZ@dq*`Ss8ZO$LdVw#mis)IsN(O zla;2e(YyWjrtB}q`mCV(OW!t1r&1>$YRFyS~2dL@sUSNv=CK zT0GR7T$ZB_VozR>^8-xJ&fNu~H%H{nWd<{T6s~6k%d9G{pS-<970eDSae>nElQrRD z;?|5za?H3gv;;J33osmT1To>+n-!eBC-;=f*kk5mh%QE;`i4f3HmEN2JPkAhn5QSp zl*?FRh9I)d%)p`pY6c=afx3a=339>YkWv9fSq7L6kgYzLIwqHu8ciydW7^>`S)tTq z@(LjHc>d%QrG89@3MNaG`7zZOPR;;Q@}-k^0I7>*lR3%_fPp78*{hs~r>dNRp(MA! vP_HC2ZSsb4C#Hktlb4n2O|~ePW8$co98sqPzOqnk$PuTpy;i2B-FlGTcJ_Z?voW#78;>42pBqP0&%(T!DP6p;} z$`kxS>LxSm+fKfiug=`HrDgK({2yTYTfr{o^Rg2*Z!Vn63=-HJT)LhSEW=t}KUt_k zm3cz(#K~*QU6|*CY0Js;%DI_eS52I3RUtijYo!Vk1H~kA5(hnl!&G`I5=e vH7b**R%jajDwFGL*!Z{@xEPd}85q8lfGh$4#phri