Skip to content
Permalink
Browse files

fix zip file reading for gdal<1.9 and add test for folder-in-zip

  • Loading branch information
etiennesky authored and jef-n committed May 21, 2012
1 parent d072885 commit 86243eb8fe0e43dfa02c050c89e8e44283240b38
Showing with 30 additions and 6 deletions.
  1. +12 −6 src/core/qgsdataitem.cpp
  2. +18 −0 tests/src/core/testziplayer.cpp
  3. BIN tests/testdata/testzip.zip
@@ -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,15 +831,17 @@ 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 );
}
}
}
CSLDestroy( papszFiles1 );

return oFiles.StealList();
// return oFiles.StealList();
return papszOFiles;
}

QVector<QgsDataItem*> QgsZipItem::createChildren( )
@@ -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"
BIN +1.1 KB (100%) tests/testdata/testzip.zip
Binary file not shown.

0 comments on commit 86243eb

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