Skip to content

Commit 21035c0

Browse files
committed
fix: move logic
1 parent d2270dc commit 21035c0

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class TestToolChecker implements DepsChecker {
8181
} else {
8282
this.telemetryProperties[TelemetryProperties.SymlinkTestToolVersionError] =
8383
versionRes.error.message;
84-
await unlinkSymlink(symlinkDir);
84+
await unlinkSymlink(symlinkDir, true);
8585
}
8686
}
8787

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ import { v3DefaultHelpLink } from "../constant/helpLink";
99
import { Messages } from "../constant/message";
1010
import { DepsCheckerError } from "../../../error/depCheck";
1111

12-
export async function unlinkSymlink(linkFilePath: string): Promise<void> {
12+
export async function unlinkSymlink(linkFilePath: string, forceUpdate = false): Promise<void> {
1313
try {
1414
const stat = await fs.lstat(linkFilePath);
1515
if (stat.isSymbolicLink()) {
1616
await fs.unlink(linkFilePath);
17+
} else {
18+
if (forceUpdate) {
19+
// For regular file or directory, remove it
20+
await fs.remove(linkFilePath);
21+
}
1722
}
1823
} catch (error: unknown) {
1924
const statError = error as { code?: string };
@@ -28,18 +33,10 @@ export async function createSymlink(
2833
linkFilePath: string,
2934
forceUpdate = false
3035
): Promise<void> {
31-
await unlinkSymlink(linkFilePath);
36+
await unlinkSymlink(linkFilePath, forceUpdate);
3237
// check if destination already exists
3338
if (await fs.pathExists(linkFilePath)) {
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-
}
39+
throw new DepsCheckerError(Messages.symlinkDirAlreadyExist(linkFilePath), v3DefaultHelpLink);
4340
}
4441

4542
return await fs.ensureSymlink(

0 commit comments

Comments
 (0)