Skip to content

Commit 48b099c

Browse files
committedJun 9, 2014
Fix #10212 (fail to handle relative paths to gzipped files)
1 parent 7c0da6d commit 48b099c

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed
 

‎src/core/qgsproject.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,12 @@ QString QgsProject::readPath( QString src ) const
14771477
QString vsiPrefix = qgsVsiPrefix( src );
14781478
if ( ! vsiPrefix.isEmpty() )
14791479
{
1480-
src.remove( 0, vsiPrefix.size() );
1480+
// unfortunately qgsVsiPrefix returns prefix also for files like "/x/y/z.gz"
1481+
// so we need to check if we really have the prefix
1482+
if ( src.startsWith( "/vsi", Qt::CaseInsensitive ) )
1483+
src.remove( 0, vsiPrefix.size() );
1484+
else
1485+
vsiPrefix.clear();
14811486
}
14821487

14831488
// relative path should always start with ./ or ../

‎tests/src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ ADD_QGIS_TEST(diagramtest testqgsdiagram.cpp)
8383
ADD_QGIS_TEST(diagramexpressiontest testqgsdiagramexpression.cpp)
8484
ADD_QGIS_TEST(expressiontest testqgsexpression.cpp)
8585
ADD_QGIS_TEST(filewritertest testqgsvectorfilewriter.cpp)
86+
ADD_QGIS_TEST(projecttest testqgsproject.cpp)
8687
ADD_QGIS_TEST(regression992 regression992.cpp)
8788
ADD_QGIS_TEST(regression1141 regression1141.cpp)
8889
ADD_QGIS_TEST(rasterlayertest testqgsrasterlayer.cpp)

‎tests/src/core/testqgsproject.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/***************************************************************************
2+
testqgsproject.cpp
3+
--------------------------------------
4+
Date : June 2014
5+
Copyright : (C) 2014 by Martin Dobias
6+
Email : wonder.sk at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
#include <QtTest>
16+
#include <QObject>
17+
18+
#include <qgsapplication.h>
19+
#include <qgsproject.h>
20+
21+
22+
class TestQgsProject : public QObject
23+
{
24+
Q_OBJECT
25+
private slots:
26+
void initTestCase();// will be called before the first testfunction is executed.
27+
void cleanupTestCase();// will be called after the last testfunction was executed.
28+
void init();// will be called before each testfunction is executed.
29+
void cleanup();// will be called after every testfunction.
30+
31+
void testReadPath();
32+
};
33+
34+
void TestQgsProject::init()
35+
{
36+
}
37+
38+
void TestQgsProject::cleanup()
39+
{
40+
// will be called after every testfunction.
41+
}
42+
43+
void TestQgsProject::initTestCase()
44+
{
45+
// Runs once before any tests are run
46+
}
47+
48+
49+
void TestQgsProject::cleanupTestCase()
50+
{
51+
// Runs once after all tests are run
52+
}
53+
54+
void TestQgsProject::testReadPath()
55+
{
56+
QgsProject* prj = QgsProject::instance();
57+
// this is a bit hacky as we do not really load such project
58+
prj->setFileName( "/home/qgis/a-project-file.qgs" ); // not expected to exist
59+
// make sure we work with relative paths!
60+
prj->writeEntry( "Paths", "Absolute", false );
61+
62+
QCOMPARE( prj->readPath( "./x.shp" ), QString( "/home/qgis/x.shp" ) );
63+
QCOMPARE( prj->readPath( "../x.shp" ), QString( "/home/x.shp" ) );
64+
65+
// TODO: old style (seems QGIS < 1.3) - needs existing project file and existing file
66+
// QCOMPARE( prj->readPath( "x.shp" ), QString( "/home/qgis/x.shp" ) );
67+
68+
// VSI: /vsizip, /vsitar, /vsigzip, *.zip, *.gz, *.tgz, ...
69+
70+
QCOMPARE( prj->readPath( "./x.gz" ), QString( "/home/qgis/x.gz" ) );
71+
QCOMPARE( prj->readPath( "/vsigzip/./x.gz" ), QString( "/vsigzip//home/qgis/x.gz" ) ); // not sure how useful this really is...
72+
73+
}
74+
75+
76+
QTEST_MAIN( TestQgsProject )
77+
#include "moc_testqgsproject.cxx"

0 commit comments

Comments
 (0)
Please sign in to comment.