mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
fix zip file reading for gdal<1.9 and add test for folder-in-zip
This commit is contained in:
parent
1b6b841545
commit
f11878b627
@ -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<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
tests/testdata/testzip.zip
vendored
BIN
tests/testdata/testzip.zip
vendored
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user