Skip to content

Commit d2270dc

Browse files
committed
fix: force remove symbol link destination for test tool install
1 parent e1f4e03 commit d2270dc

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

packages/fx-core/src/component/deps-checker/internal/testToolChecker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class TestToolChecker implements DepsChecker {
9797
);
9898
this.telemetryProperties[TelemetryProperties.SelectedPortableTestToolVersion] = version;
9999
if (symlinkDir) {
100-
await createSymlink(portablePath, symlinkDir);
100+
await createSymlink(portablePath, symlinkDir, true);
101101
return await this.getSuccessDepsInfo(version, symlinkDir);
102102
} else {
103103
return await this.getSuccessDepsInfo(version, portablePath);
@@ -200,7 +200,7 @@ export class TestToolChecker implements DepsChecker {
200200
await rename(tmpPath, portablePath);
201201

202202
if (symlinkDir) {
203-
await createSymlink(portablePath, symlinkDir);
203+
await createSymlink(portablePath, symlinkDir, true);
204204
}
205205

206206
await this.writeInstallInfoFile(projectPath);

packages/fx-core/src/component/deps-checker/util/fileHelper.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ export async function unlinkSymlink(linkFilePath: string): Promise<void> {
1414
const stat = await fs.lstat(linkFilePath);
1515
if (stat.isSymbolicLink()) {
1616
await fs.unlink(linkFilePath);
17-
} else {
18-
// For regular file or directory, remove it
19-
await fs.remove(linkFilePath);
2017
}
2118
} catch (error: unknown) {
2219
const statError = error as { code?: string };
@@ -26,11 +23,23 @@ export async function unlinkSymlink(linkFilePath: string): Promise<void> {
2623
}
2724
}
2825

29-
export async function createSymlink(target: string, linkFilePath: string): Promise<void> {
26+
export async function createSymlink(
27+
target: string,
28+
linkFilePath: string,
29+
forceUpdate = false
30+
): Promise<void> {
3031
await unlinkSymlink(linkFilePath);
3132
// check if destination already exists
3233
if (await fs.pathExists(linkFilePath)) {
33-
throw new DepsCheckerError(Messages.symlinkDirAlreadyExist(linkFilePath), v3DefaultHelpLink);
34+
if (!forceUpdate) {
35+
throw new DepsCheckerError(Messages.symlinkDirAlreadyExist(linkFilePath), v3DefaultHelpLink);
36+
}
37+
try {
38+
// For regular file or directory, unlink will fail so we remove it
39+
await fs.remove(linkFilePath);
40+
} catch {
41+
throw new DepsCheckerError(Messages.symlinkDirAlreadyExist(linkFilePath), v3DefaultHelpLink);
42+
}
3443
}
3544

3645
return await fs.ensureSymlink(

0 commit comments

Comments
 (0)