Skip to content

Commit 4a75a95

Browse files
committedDec 16, 2013
fix project saving and reading of vsizip paths (fixes #6369)
1 parent cf39d71 commit 4a75a95

File tree

5 files changed

+43
-28
lines changed

5 files changed

+43
-28
lines changed
 

‎src/core/qgis.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,19 @@ bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs )
176176
return ! qgsVariantLessThan( lhs, rhs );
177177
}
178178

179+
QString qgsVsiPrefix( QString path )
180+
{
181+
if ( path.startsWith( "/vsizip/", Qt::CaseInsensitive ) ||
182+
path.endsWith( ".zip", Qt::CaseInsensitive ) )
183+
return "/vsizip/";
184+
else if ( path.startsWith( "/vsitar/", Qt::CaseInsensitive ) ||
185+
path.endsWith( ".tar", Qt::CaseInsensitive ) ||
186+
path.endsWith( ".tar.gz", Qt::CaseInsensitive ) ||
187+
path.endsWith( ".tgz", Qt::CaseInsensitive ) )
188+
return "/vsitar/";
189+
else if ( path.startsWith( "/vsigzip/", Qt::CaseInsensitive ) ||
190+
path.endsWith( ".gz", Qt::CaseInsensitive ) )
191+
return "/vsigzip/";
192+
else
193+
return "";
194+
}

‎src/core/qgis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs );
324324

325325
bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs );
326326

327+
QString qgsVsiPrefix( QString path );
328+
327329
/** Allocates size bytes and returns a pointer to the allocated memory.
328330
Works like C malloc() but prints debug message by QgsLogger if allocation fails.
329331
@param size size in bytes

‎src/core/qgsdataitem.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -954,23 +954,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren()
954954
return children;
955955
}
956956

957-
QString QgsZipItem::vsiPrefix( QString path )
958-
{
959-
if ( path.startsWith( "/vsizip/", Qt::CaseInsensitive ) ||
960-
path.endsWith( ".zip", Qt::CaseInsensitive ) )
961-
return "/vsizip/";
962-
else if ( path.startsWith( "/vsitar/", Qt::CaseInsensitive ) ||
963-
path.endsWith( ".tar", Qt::CaseInsensitive ) ||
964-
path.endsWith( ".tar.gz", Qt::CaseInsensitive ) ||
965-
path.endsWith( ".tgz", Qt::CaseInsensitive ) )
966-
return "/vsitar/";
967-
else if ( path.startsWith( "/vsigzip/", Qt::CaseInsensitive ) ||
968-
path.endsWith( ".gz", Qt::CaseInsensitive ) )
969-
return "/vsigzip/";
970-
else
971-
return "";
972-
}
973-
974957
QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString path, QString name )
975958
{
976959
QSettings settings;

‎src/core/qgsdataitem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class CORE_EXPORT QgsZipItem : public QgsDataCollectionItem
316316
static QVector<dataItem_t *> mDataItemPtr;
317317
static QStringList mProviderNames;
318318

319-
static QString vsiPrefix( QString uri );
319+
static QString vsiPrefix( QString uri ) { return qgsVsiPrefix( uri ); }
320320

321321
static QgsDataItem* itemFromPath( QgsDataItem* parent, QString path, QString name );
322322

‎src/core/qgsproject.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,13 @@ QString QgsProject::readPath( QString src ) const
13661366
return src;
13671367
}
13681368

1369+
// if this is a VSIFILE, remove the VSI prefix and append to final result
1370+
QString vsiPrefix = qgsVsiPrefix( src );
1371+
if ( ! vsiPrefix.isEmpty() )
1372+
{
1373+
src.remove(0, vsiPrefix.size());
1374+
}
1375+
13691376
// relative path should always start with ./ or ../
13701377
if ( !src.startsWith( "./" ) && !src.startsWith( "../" ) )
13711378
{
@@ -1375,13 +1382,13 @@ QString QgsProject::readPath( QString src ) const
13751382
( src[0].isLetter() && src[1] == ':' ) )
13761383
{
13771384
// UNC or absolute path
1378-
return src;
1385+
return vsiPrefix + src;
13791386
}
13801387
#else
13811388
if ( src[0] == '/' )
13821389
{
13831390
// absolute path
1384-
return src;
1391+
return vsiPrefix + src;
13851392
}
13861393
#endif
13871394

@@ -1391,17 +1398,17 @@ QString QgsProject::readPath( QString src ) const
13911398
// from the filename.
13921399
QString home = homePath();
13931400
if ( home.isNull() )
1394-
return src;
1401+
return vsiPrefix + src;
13951402

13961403
QFileInfo fi( home + "/" + src );
13971404

13981405
if ( !fi.exists() )
13991406
{
1400-
return src;
1407+
return vsiPrefix + src;
14011408
}
14021409
else
14031410
{
1404-
return fi.canonicalFilePath();
1411+
return vsiPrefix + fi.canonicalFilePath();
14051412
}
14061413
}
14071414

@@ -1410,7 +1417,7 @@ QString QgsProject::readPath( QString src ) const
14101417

14111418
if ( projPath.isEmpty() )
14121419
{
1413-
return src;
1420+
return vsiPrefix + src;
14141421
}
14151422

14161423
#if defined(Q_OS_WIN)
@@ -1452,13 +1459,13 @@ QString QgsProject::readPath( QString src ) const
14521459
projElems.prepend( "" );
14531460
#endif
14541461

1455-
return projElems.join( "/" );
1462+
return vsiPrefix + projElems.join( "/" );
14561463
}
14571464

14581465
// return the absolute or relative path to write it to the project file
14591466
QString QgsProject::writePath( QString src ) const
14601467
{
1461-
if ( readBoolEntry( "Paths", "/Absolute", false ) || src.isEmpty() )
1468+
if ( readBoolEntry( "Paths", "/Absolute", false ) || src.isEmpty() )
14621469
{
14631470
return src;
14641471
}
@@ -1467,10 +1474,17 @@ QString QgsProject::writePath( QString src ) const
14671474
QString projPath = fileName();
14681475

14691476
if ( projPath.isEmpty() )
1470-
{
1477+
{
14711478
return src;
14721479
}
14731480

1481+
// if this is a VSIFILE, remove the VSI prefix and append to final result
1482+
QString vsiPrefix = qgsVsiPrefix( src );
1483+
if ( ! vsiPrefix.isEmpty() )
1484+
{
1485+
srcPath.remove(0, vsiPrefix.size());
1486+
}
1487+
14741488
#if defined( Q_OS_WIN )
14751489
const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
14761490

@@ -1533,7 +1547,7 @@ QString QgsProject::writePath( QString src ) const
15331547
srcElems.insert( 0, "." );
15341548
}
15351549

1536-
return srcElems.join( "/" );
1550+
return vsiPrefix + srcElems.join( "/" );
15371551
}
15381552

15391553
void QgsProject::setError( QString errorMessage )

0 commit comments

Comments
 (0)
Please sign in to comment.