Skip to content

Commit ff6853e

Browse files
committed
[new] lock opened project
1 parent e589945 commit ff6853e

5 files changed

Lines changed: 23 additions & 6 deletions

File tree

lib/node-utility

src/EIDEProject.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ import { md5, copyObject, compareVersion } from './utility';
5959
import { ResInstaller } from './ResInstaller';
6060
import {
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';
6465
import { SettingManager } from './SettingManager';
6566
import { ExeCmd } from '../lib/node-utility/Executable';
6667
import { jsonc } from 'jsonc';
6768
import * as iconv from 'iconv-lite';
6869
import * as globmatch from 'micromatch'
6970
import { ICompileOptions, EventData, CurrentDevice, ArmBaseCompileConfigModel } from './EIDEProjectModules';
71+
import * as FileLock from '../lib/node-utility/FileLock';
7072

7173
export 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();

src/EIDEProjectExplorer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
20222022
} catch (err) {
20232023
GlobalEvent.emit('msg', newMessage('Warning', project_load_failed));
20242024
GlobalEvent.emit('globalLog', ExceptionToMessage(err, 'Error'));
2025+
GlobalEvent.emit('globalLog.show');
20252026
return undefined;
20262027
}
20272028
}

src/StringTable.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ export const project_exist_txt = [
563563
][langIndex];
564564

565565
export const project_load_failed = [
566-
'项目加载失败 !',
567-
'Project Load Failed !'
566+
'项目加载失败 ! 打开输出面板查看日志以获取更多细节',
567+
'Project Load Failed ! Please open output panel and check log'
568568
][langIndex];
569569

570570
export const project_is_opened = [
@@ -587,6 +587,11 @@ export const view_str$msg$err_ewt_hash = [
587587
`This template has incorrect hash and we can't install it !`
588588
][langIndex];
589589

590+
export const view_str$prompt$project_is_opened_by_another = [
591+
`无法锁定项目 '{path}',这个项目可能已被其他 EIDE 实例打开了 !`,
592+
`Can't lock project: '{path}', maybe this project has been opened by another EIDE instance !`
593+
][langIndex];
594+
590595
//---------------Select string------------------
591596

592597
export const later_text = [

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ let prj_count: number = 0;
11461146
function RegisterGlobalEvent() {
11471147

11481148
LogAnalyzer.on('Log', (msg) => {
1149-
// no workspace, log to output pannel
1149+
// no workspace, log to output panel
11501150
if (LogAnalyzer.GetInstance().getLogListenerCount() < 2) {
11511151
GlobalEvent.emit('globalLog', msg);
11521152
}

0 commit comments

Comments
 (0)