MCPcopy Index your code
hub / github.com/nodejs/node / symlinkSync

Function symlinkSync

lib/fs.js:2230–2259  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

2228 * @returns {void}
2229 */
2230function 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`

Calls 8

isEnabledMethod · 0.80
statSyncFunction · 0.70
hasMethod · 0.65
symlinkSyncMethod · 0.45
resolveMethod · 0.45
isDirectoryMethod · 0.45
symlinkMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…