@@ -59,14 +59,16 @@ import { md5, copyObject, compareVersion } from './utility';
5959import { ResInstaller } from './ResInstaller' ;
6060import {
6161 view_str$prompt$not_found_compiler , view_str$operation$name_can_not_be_blank ,
62- view_str$operation$name_can_not_have_invalid_char
62+ view_str$operation$name_can_not_have_invalid_char ,
63+ view_str$prompt$project_is_opened_by_another ,
6364} from './StringTable' ;
6465import { SettingManager } from './SettingManager' ;
6566import { ExeCmd } from '../lib/node-utility/Executable' ;
6667import { jsonc } from 'jsonc' ;
6768import * as iconv from 'iconv-lite' ;
6869import * as globmatch from 'micromatch'
6970import { ICompileOptions , EventData , CurrentDevice , ArmBaseCompileConfigModel } from './EIDEProjectModules' ;
71+ import * as FileLock from '../lib/node-utility/FileLock' ;
7072
7173export class CheckError extends Error {
7274}
@@ -807,6 +809,8 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
807809
808810 private builtinEnvVars : { [ key : string ] : ( ) => string } = { } ;
809811
812+ private lock_handle : number | undefined ;
813+
810814 ////////////////////////////////// cpptools provider interface ///////////////////////////////////
811815
812816 name : string = 'eide' ;
@@ -1177,7 +1181,7 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
11771181 /**
11781182 * get output dir top root name. like: `build`
11791183 */
1180- getOutputRoot ( ) : string {
1184+ getOutputRoot ( ) : string {
11811185 return this . GetConfiguration ( ) . getOutDirRoot ( ) ;
11821186 }
11831187
@@ -1265,6 +1269,12 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
12651269 }
12661270
12671271 async Load ( wsFile : File ) {
1272+
1273+ this . lock_handle = FileLock . lock ( [ os . tmpdir ( ) , `${ md5 ( wsFile . path ) } .lock` ] . join ( NodePath . sep ) ) ;
1274+ if ( this . lock_handle == undefined ) {
1275+ throw new Error ( view_str$prompt$project_is_opened_by_another . replace ( '{path}' , wsFile . path ) ) ;
1276+ }
1277+
12681278 await this . BeforeLoad ( wsFile ) ;
12691279 this . LoadConfigurations ( wsFile ) ;
12701280 this . loadProjectDirectory ( ) ;
@@ -1278,6 +1288,7 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
12781288 }
12791289
12801290 Close ( ) {
1291+ if ( this . lock_handle ) FileLock . unlock ( this . lock_handle ) ;
12811292 this . sourceRoots . DisposeAll ( ) ;
12821293 this . configMap . Dispose ( ) ;
12831294 this . eideDirWatcher ?. Close ( ) ;
0 commit comments