Skip to content

Commit 9f02d0d

Browse files
author
jef
committed
workaround for non-functional lock.exe on windows (fixes #808)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9245 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent ba96ab1 commit 9f02d0d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/providers/grass/qgsgrass.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,20 @@ QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, Q
452452

453453
QString lock = mapsetPath + "/.gislock";
454454
QFile lockFile( lock );
455+
#if WIN32
456+
// lock on Windows doesn't support locking (see #808)
457+
if( lockFile.exists() )
458+
return QObject::tr( "Mapset is already in use." );
459+
460+
lockFile.open(QIODevice::WriteOnly);
461+
#ifndef _MSC_VER
462+
int pid = getpid();
463+
#else
464+
int pid = GetCurrentProcessId();
465+
#endif
466+
lockFile.write( QString("%1").arg( pid ).toLocal8Bit() );
467+
lockFile.close();
468+
#else
455469
Q3Process *process = new Q3Process();
456470
process->addArgument( gisBase + "/etc/lock" ); // lock program
457471
process->addArgument( lock ); // lock file
@@ -473,17 +487,13 @@ QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, Q
473487
// TODO better wait
474488
while ( process->isRunning() ) { }
475489

476-
#ifndef WIN32
477490
int status = process->exitStatus();
478491
QgsDebugMsg( QString( "status = %1" ).arg( status ) );
479-
#endif
480492
delete process;
481493

482-
483-
// TODO WIN32 (lock.exe does not work properly?)
484-
#ifndef WIN32
485-
if ( status > 0 ) return QObject::tr( "Mapset is already in use." );
486-
#endif
494+
if ( status > 0 )
495+
return QObject::tr( "Mapset is already in use." );
496+
#endif // !WIN32
487497

488498
// Create temporary directory
489499
QFileInfo info( mapsetPath );

0 commit comments

Comments
 (0)