Skip to content

Commit 7cc88a2

Browse files
authored
Merge pull request #14276 from OfficeDev/qinzhouxu/link
fix: symbol link creation issue for test tool install
2 parents 524a8d3 + 4a9ff0f commit 7cc88a2

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

.github/workflows/env-checker-ci-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
## Details about this issue: https://github.com/npm/cli/wiki/%22cb()-never-called%3F--I'm-having-the-same-problem!%22
3434
### tl;dr: This error is not one thing, but a category of errors. It means "something broke and we didn't have a way to catch it". We will always need a lot of detail to reproduce an error like this, or we cannot ever fix it. Every instance is unique, and your cb() never called is nothing like any other.
3535
matrix:
36-
os: [windows-latest, macos-11, ubuntu-latest]
36+
os: [windows-latest, macos-latest, ubuntu-latest]
3737
node-version: [18]
3838
func-version: [none]
3939
dotnet-version: [none]

.github/workflows/env-checker-ci-schedule.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
### tl;dr: This error is not one thing, but a category of errors. It means "something broke and we didn't have a way to catch it". We will always need a lot of detail to reproduce an error like this, or we cannot ever fix it. Every instance is unique, and your cb() never called is nothing like any other.
2020
# macos-latest is 10.15. We need to test 11 as well.
2121
matrix:
22-
os: [windows-latest, macos-latest, macos-11, ubuntu-latest]
22+
os: [windows-latest, macos-latest, ubuntu-latest]
2323
node-version: [16, 18, 20]
2424
func-version: [none, "3", "4", "4.0.4670", "~4.0.5174"]
2525
max-parallel: 30

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

Lines changed: 3 additions & 3 deletions
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

@@ -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: 12 additions & 3 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 };
@@ -23,8 +28,12 @@ export async function unlinkSymlink(linkFilePath: string): Promise<void> {
2328
}
2429
}
2530

26-
export async function createSymlink(target: string, linkFilePath: string): Promise<void> {
27-
await unlinkSymlink(linkFilePath);
31+
export async function createSymlink(
32+
target: string,
33+
linkFilePath: string,
34+
forceUpdate = false
35+
): Promise<void> {
36+
await unlinkSymlink(linkFilePath, forceUpdate);
2837
// check if destination already exists
2938
if (await fs.pathExists(linkFilePath)) {
3039
throw new DepsCheckerError(Messages.symlinkDirAlreadyExist(linkFilePath), v3DefaultHelpLink);

0 commit comments

Comments
 (0)