Skip to content

Commit 48bd8a6

Browse files
committed
update: 清理文件锁相关内容 (#568)
1 parent f2db67d commit 48bd8a6

File tree

7 files changed

+0
-83
lines changed

7 files changed

+0
-83
lines changed

package-lock.json

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@
316316
},
317317
"devDependencies": {
318318
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
319-
"@types/lockfile": "^1.0.4",
320319
"@types/node": "^24",
321320
"@types/stylis": "^4.2.7",
322321
"@types/uglify-js": "^3.17.5",
@@ -334,7 +333,6 @@
334333
"dependencies": {
335334
"@vscode/sudo-prompt": "^9.3.1",
336335
"fast-glob": "^3.3.3",
337-
"lockfile": "^1.0.4",
338336
"stylis": "^4.3.6",
339337
"uglify-js": "^3.19.3"
340338
}

src/background/CssFile.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ export class CssFile {
177177
*/
178178
public async uninstall(): Promise<boolean> {
179179
try {
180-
await _.lock();
181180
let content = await this.getContent();
182181
content = this.clearContent(content);
183182
// 异常case return
@@ -188,8 +187,6 @@ export class CssFile {
188187
} catch (ex) {
189188
console.log(ex);
190189
return false;
191-
} finally {
192-
await _.unlock();
193190
}
194191
}
195192
}

src/background/PatchFile/PatchFile.base.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,11 @@ export abstract class AbsPatchFile {
146146

147147
public async restore() {
148148
try {
149-
await _.lock();
150149
let content = await this.getContent();
151150
content = this.cleanPatches(content);
152151
return await this.write(content);
153152
} catch {
154153
return false;
155-
} finally {
156-
await _.unlock();
157154
}
158155
}
159156
}

src/background/PatchFile/PatchFile.javascript.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { _ } from '../../utils';
21
import { BACKGROUND_VER, VERSION } from '../../utils/constants';
32
import { AbsPatchFile } from './PatchFile.base';
43

@@ -15,7 +14,6 @@ import { AbsPatchFile } from './PatchFile.base';
1514
export class JsPatchFile extends AbsPatchFile {
1615
public async applyPatches(patchContent: string): Promise<boolean> {
1716
try {
18-
await _.lock();
1917
const curContent = await this.getContent();
2018
let content = this.cleanPatches(curContent);
2119
content += [
@@ -33,8 +31,6 @@ export class JsPatchFile extends AbsPatchFile {
3331
return await this.write(content);
3432
} catch {
3533
return false;
36-
} finally {
37-
await _.unlock();
3834
}
3935
}
4036

src/utils/constants.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@ export const EXTENSION_NAME: string = pkg.name;
2020
/** 扩展ID */
2121
export const EXTENSION_ID = `${PUBLISHER}.${EXTENSION_NAME}`;
2222

23-
/** 文件锁路径 */
24-
export const LOCK_PATH = path.join(__dirname, '../../', `${EXTENSION_ID}.lock`);
25-
2623
/** 版本临时文件,存放js路径、标识初次安装 */
2724
export const TOUCH_JSFILE_PATH = path.join(__dirname, `../../vscb.${VERSION}.js.touch`);

src/utils/index.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import sudo from '@vscode/sudo-prompt';
2-
import lockfile from 'lockfile';
32

4-
import { LOCK_PATH } from './constants';
53
import { vsc } from './vsc';
64

75
export namespace _ {
@@ -32,48 +30,6 @@ export namespace _ {
3230
});
3331
}
3432

35-
/**
36-
* 添加文件锁
37-
*
38-
* @export
39-
* @return {*}
40-
*/
41-
export function lock() {
42-
return new Promise<void>((resolve, reject) => {
43-
lockfile.lock(
44-
LOCK_PATH,
45-
{
46-
// When multiple VSCode instances are running, all instances' commands need to be executed within the `wait` time
47-
// 在打开了多个vscode实例时,需要所有实例的命令在`wait`时间内执行完毕
48-
wait: 1000 * 30
49-
},
50-
err => {
51-
if (err) {
52-
return reject(err);
53-
}
54-
resolve();
55-
}
56-
);
57-
});
58-
}
59-
60-
/**
61-
* 取消文件锁
62-
*
63-
* @export
64-
* @return {*}
65-
*/
66-
export function unlock() {
67-
return new Promise<void>((resolve, reject) => {
68-
lockfile.unlock(LOCK_PATH, err => {
69-
if (err) {
70-
return reject(err);
71-
}
72-
resolve();
73-
});
74-
});
75-
}
76-
7733
/**
7834
* 提权运行
7935
*

0 commit comments

Comments
 (0)