Skip to content

Commit

Permalink
fix: unlink ENOENT (#59)
Browse files Browse the repository at this point in the history
Fixes #57
  • Loading branch information
KSXGitHub authored Oct 29, 2024
1 parent b0c6bc3 commit af5d69f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import betterPathResolve = require('better-path-resolve')
import { promises as fs, symlinkSync, mkdirSync, readlinkSync, unlinkSync } from 'fs'
import util = require('util')
import pathLib = require('path')
import renameOverwrite = require('rename-overwrite')

Expand Down Expand Up @@ -103,7 +104,13 @@ async function forceSymlink (
if (opts?.overwrite === false) {
throw initialErr
}
await fs.unlink(path)
try {
await fs.unlink(path)
} catch (error) {
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') {
throw error
}
}
return await forceSymlink(target, path, opts)
}

Expand Down Expand Up @@ -194,6 +201,12 @@ function forceSymlinkSync (
if (opts?.overwrite === false) {
throw initialErr
}
unlinkSync(path)
try {
unlinkSync(path)
} catch (error) {
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') {
throw error
}
}
return forceSymlinkSync(target, path, opts)
}

0 comments on commit af5d69f

Please sign in to comment.