Skip to content
Permalink
Browse files

[GRASS] fixed running modules in mapsets not owned by user

  • Loading branch information
blazek committed Oct 19, 2015
1 parent 6261a38 commit 483f3ee6b393f73410e7adac365028463cffc7da
Showing with 12 additions and 32 deletions.
  1. +9 −19 src/providers/grass/qgsgrass.cpp
  2. +3 −13 tests/src/providers/grass/testqgsgrassprovider.cpp
@@ -1922,35 +1922,25 @@ QProcess *QgsGrass::startModule( const QString& gisdbase, const QString& locati

QString error = tr( "Cannot start module" ) + "\n" + tr( "command: %1 %2" ).arg( module, arguments.join( " " ) );

// Modules must be run in a mapset owned by user, because each module calls G_gisinit()
// which checks if G_mapset() is owned by user.
QString ownedMapset = mapset;
if ( ownedMapset.isEmpty() )
QTextStream out( &gisrcFile );
out << "GISDBASE: " << gisdbase << "\n";
out << "LOCATION_NAME: " << location << "\n";
if ( mapset.isEmpty() )
{
Q_FOREACH ( const QString& ms, mapsets( gisdbase, location ) )
{
if ( isOwner( gisdbase, location, ms ) )
{
ownedMapset = ms;
}
}
out << "MAPSET: PERMANENT\n";
}
if ( ownedMapset.isEmpty() )
else
{
throw QgsGrass::Exception( error + "\n" + tr( "Cannot find a mapset owned by current user" ) );
out << "MAPSET: " << mapset << "\n";
}

QTextStream out( &gisrcFile );
out << "GISDBASE: " << gisdbase << "\n";
out << "LOCATION_NAME: " << location << "\n";
//out << "MAPSET: PERMANENT\n";
out << "MAPSET: " << ownedMapset << "\n";
out.flush();
QgsDebugMsg( gisrcFile.fileName() );
gisrcFile.close();
QStringList environment = QProcess::systemEnvironment();
environment.append( "GISRC=" + gisrcFile.fileName() );
environment.append( "GRASS_MESSAGE_FORMAT=gui" );
// Normaly modules must be run in a mapset owned by user, because each module calls G_gisinit()
// which checks if G_mapset() is owned by user. The check is disabled by GRASS_SKIP_MAPSET_OWNER_CHECK.
environment.append( "GRASS_SKIP_MAPSET_OWNER_CHECK=1" );

process->setEnvironment( environment );
@@ -496,15 +496,6 @@ void TestQgsGrassProvider::info()
reportHeader( "TestQgsGrassProvider::info" );
bool ok = true;

// GRASS modules must be run in a mapset owned by user, the source code may have different user.
QString tmpGisdbase;
if ( !copyLocation( tmpGisdbase ) )
{
reportRow( "cannot copy location" );
GVERIFY( false );
return;
}

QgsRectangle expectedExtent( -5, -5, 5, 5 );
QMap<QString, QgsRasterBandStats> expectedStats;
QgsRasterBandStats es;
@@ -522,7 +513,7 @@ void TestQgsGrassProvider::info()
es = expectedStats.value( map );
// TODO: QgsGrass::info() may open dialog window on error which blocks tests
QString error;
QHash<QString, QString> info = QgsGrass::info( tmpGisdbase, mLocation, "test", map, QgsGrassObject::Raster, "stats",
QHash<QString, QString> info = QgsGrass::info( mGisdbase, mLocation, "test", map, QgsGrassObject::Raster, "stats",
expectedExtent, 10, 10, 5000, error );
if ( !error.isEmpty() )
{
@@ -541,7 +532,7 @@ void TestQgsGrassProvider::info()
compare( es.minimumValue, s.minimumValue, ok );
compare( es.maximumValue, s.maximumValue, ok );

QgsRectangle extent = QgsGrass::extent( tmpGisdbase, mLocation, "test", map, QgsGrassObject::Raster, error );
QgsRectangle extent = QgsGrass::extent( mGisdbase, mLocation, "test", map, QgsGrassObject::Raster, error );
reportRow( "expectedExtent: " + expectedExtent.toString() );
reportRow( "extent: " + extent.toString() );
if ( !error.isEmpty() )
@@ -561,7 +552,7 @@ void TestQgsGrassProvider::info()

reportRow( "expectedCrs: " + expectedCrs.toWkt() );
QString error;
QgsCoordinateReferenceSystem crs = QgsGrass::crs( tmpGisdbase, mLocation, error );
QgsCoordinateReferenceSystem crs = QgsGrass::crs( mGisdbase, mLocation, error );
if ( !error.isEmpty() )
{
ok = false;
@@ -583,7 +574,6 @@ void TestQgsGrassProvider::info()
}
}
}
removeRecursively( tmpGisdbase );
GVERIFY( ok );
}

0 comments on commit 483f3ee

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