Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 86243eb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/core/qgsdataitem.cpp
Expand Up @@ -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;
Expand All @@ -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 ) )
Expand All @@ -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() );
Expand All @@ -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( )
Expand Down
18 changes: 18 additions & 0 deletions tests/src/core/testziplayer.cpp
Expand Up @@ -77,6 +77,8 @@ class TestZipLayer: public QObject
void testGZipItemVectorTransparency();
void testZipItemRasterTransparency();
void testGZipItemRasterTransparency();
//make sure items inside subfolders can be read
void testZipItemSubfolder();
};


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Binary file modified tests/testdata/testzip.zip
Binary file not shown.

0 comments on commit 86243eb

Please sign in to comment.