Skip to content

Commit a211d66

Browse files
author
jef
committedSep 5, 2009
fix path corruption in GRASS on windows
git-svn-id: http://svn.osgeo.org/qgis/trunk@11570 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3bb542e commit a211d66

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
 

‎src/providers/grass/qgsgrass.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ extern "C"
4242
QString GRASS_EXPORT QgsGrass::shortPath( const QString &path )
4343
{
4444
TCHAR buf[MAX_PATH];
45-
GetShortPathName( path.toUtf8().constData(), buf, MAX_PATH );
45+
int len = GetShortPathName( path.toUtf8().constData(), buf, MAX_PATH );
46+
47+
if ( len == 0 || len > MAX_PATH )
48+
{
49+
QgsDebugMsg( QString( "GetShortPathName('%1') failed with %2: %3" )
50+
.arg( path ).arg( len ).arg( GetLastError() ) );
51+
return path;
52+
}
53+
4654
QString res = QString::fromUtf8( buf );
4755
return res;
4856
}
@@ -173,7 +181,7 @@ void GRASS_EXPORT QgsGrass::init( void )
173181
QgsDebugMsg( QString( "Valid GRASS gisBase is: %1" ).arg( gisBase ) );
174182
QString gisBaseEnv = "GISBASE=" + gisBase;
175183
/* _Correct_ putenv() implementation is not making copy! */
176-
char *gisBaseEnvChar = new char[gisBaseEnv.length()+1];
184+
char *gisBaseEnvChar = new char[gisBaseEnv.toUtf8().length()+1];
177185
strcpy( gisBaseEnvChar, gisBaseEnv.toUtf8().constData() );
178186
putenv( gisBaseEnvChar );
179187

@@ -198,14 +206,15 @@ void GRASS_EXPORT QgsGrass::init( void )
198206

199207
// Add path to MSYS bin
200208
// Warning: MSYS sh.exe will translate this path to '/bin'
201-
path.append( sep + shortPath( QCoreApplication::applicationDirPath() + "/msys/bin/" ) );
209+
if ( QFileInfo( QCoreApplication::applicationDirPath() + "/msys/bin/" ).isDir() )
210+
path.append( sep + shortPath( QCoreApplication::applicationDirPath() + "/msys/bin/" ) );
202211
#endif
203212

204213
QString p = getenv( "PATH" );
205214
path.append( sep + p );
206215

207216
QgsDebugMsg( QString( "set PATH: %1" ).arg( path ) );
208-
char *pathEnvChar = new char[path.length()+1];
217+
char *pathEnvChar = new char[path.toUtf8().length()+1];
209218
strcpy( pathEnvChar, path.toUtf8().constData() );
210219
putenv( pathEnvChar );
211220

@@ -214,7 +223,7 @@ void GRASS_EXPORT QgsGrass::init( void )
214223
QString pp = getenv( "PATH" );
215224
pythonpath.append( sep + pp );
216225
QgsDebugMsg( QString( "set PYTHONPATH: %1" ).arg( pythonpath ) );
217-
char *pythonpathEnvChar = new char[pythonpath.length()+1];
226+
char *pythonpathEnvChar = new char[pythonpath.toUtf8().length()+1];
218227
strcpy( pythonpathEnvChar, pythonpath.toUtf8().constData() );
219228
putenv( pythonpathEnvChar );
220229

0 commit comments

Comments
 (0)
Please sign in to comment.