* Synchronously creates the link called `path` * pointing to `target`. * @param {string | Buffer | URL} target * @param {string | Buffer | URL} path * @param {string | null} [type] * @returns {void}
(target, path, type)
| 2228 | * @returns {void} |
| 2229 | */ |
| 2230 | function symlinkSync(target, path, type) { |
| 2231 | const h = vfsState.handlers; |
| 2232 | if (h !== null) { |
| 2233 | const result = h.symlinkSync(target, path, type); |
| 2234 | if (result !== undefined) return; |
| 2235 | } |
| 2236 | validateOneOf(type, 'type', ['dir', 'file', 'junction', null, undefined]); |
| 2237 | if (isWindows && type == null) { |
| 2238 | const absoluteTarget = pathModule.resolve(`${path}`, '..', `${target}`); |
| 2239 | if (statSync(absoluteTarget, { throwIfNoEntry: false })?.isDirectory()) { |
| 2240 | type = 'dir'; |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | // Due to the nature of Node.js runtime, symlinks has different edge cases that can bypass |
| 2245 | // the permission model security guarantees. Thus, this API is disabled unless fs.read |
| 2246 | // and fs.write permission has been given. |
| 2247 | if (permission.isEnabled() && !permission.has('fs')) { |
| 2248 | throw new ERR_ACCESS_DENIED('fs.symlink API requires full fs.read and fs.write permissions.'); |
| 2249 | } |
| 2250 | |
| 2251 | target = getValidatedPath(target, 'target'); |
| 2252 | path = getValidatedPath(path); |
| 2253 | |
| 2254 | binding.symlink( |
| 2255 | preprocessSymlinkDestination(target, type, path), |
| 2256 | path, |
| 2257 | stringToSymlinkType(type), |
| 2258 | ); |
| 2259 | } |
| 2260 | |
| 2261 | /** |
| 2262 | * Creates a new link from the `existingPath` |
no test coverage detected
searching dependent graphs…