@@ -9,11 +9,16 @@ import { v3DefaultHelpLink } from "../constant/helpLink";
9
9
import { Messages } from "../constant/message" ;
10
10
import { DepsCheckerError } from "../../../error/depCheck" ;
11
11
12
- export async function unlinkSymlink ( linkFilePath : string ) : Promise < void > {
12
+ export async function unlinkSymlink ( linkFilePath : string , forceUpdate = false ) : Promise < void > {
13
13
try {
14
14
const stat = await fs . lstat ( linkFilePath ) ;
15
15
if ( stat . isSymbolicLink ( ) ) {
16
16
await fs . unlink ( linkFilePath ) ;
17
+ } else {
18
+ if ( forceUpdate ) {
19
+ // For regular file or directory, remove it
20
+ await fs . remove ( linkFilePath ) ;
21
+ }
17
22
}
18
23
} catch ( error : unknown ) {
19
24
const statError = error as { code ?: string } ;
@@ -28,18 +33,10 @@ export async function createSymlink(
28
33
linkFilePath : string ,
29
34
forceUpdate = false
30
35
) : Promise < void > {
31
- await unlinkSymlink ( linkFilePath ) ;
36
+ await unlinkSymlink ( linkFilePath , forceUpdate ) ;
32
37
// check if destination already exists
33
38
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 ) ;
43
40
}
44
41
45
42
return await fs . ensureSymlink (
0 commit comments