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

Function symlink

lib/internal/fs/promises.js:1737–1773  ·  view source on GitHub ↗
(target, path, type)

Source from the content-addressed store, hash-verified

1735}
1736
1737async function symlink(target, path, type) {
1738 const h = vfsState.handlers;
1739 if (h !== null) {
1740 const promise = h.symlink(target, path, type);
1741 if (promise !== undefined) { await promise; return; }
1742 }
1743 validateOneOf(type, 'type', ['dir', 'file', 'junction', null, undefined]);
1744 if (isWindows && type == null) {
1745 try {
1746 const absoluteTarget = pathModule.resolve(`${path}`, '..', `${target}`);
1747 type = (await stat(absoluteTarget)).isDirectory() ? 'dir' : 'file';
1748 } catch {
1749 // Default to 'file' if path is invalid or file does not exist
1750 type = 'file';
1751 }
1752 }
1753
1754 // Due to the nature of Node.js runtime, symlinks has different edge cases that can bypass
1755 // the permission model security guarantees. Thus, this API is disabled unless fs.read
1756 // and fs.write permission has been given.
1757 if (permission.isEnabled() && !permission.has('fs')) {
1758 throw new ERR_ACCESS_DENIED('fs.symlink API requires full fs.read and fs.write permissions.');
1759 }
1760
1761 target = getValidatedPath(target, 'target');
1762 path = getValidatedPath(path);
1763 return await PromisePrototypeThen(
1764 binding.symlink(
1765 preprocessSymlinkDestination(target, type, path),
1766 path,
1767 stringToSymlinkType(type),
1768 kUsePromises,
1769 ),
1770 undefined,
1771 handleErrorFromBinding,
1772 );
1773}
1774
1775async function fstat(handle, options = { __proto__: null, bigint: false }) {
1776 const result = await PromisePrototypeThen(

Callers 3

setupFunction · 0.90
onLinkFunction · 0.50
copyLinkFunction · 0.50

Calls 7

isEnabledMethod · 0.80
statFunction · 0.70
hasMethod · 0.65
symlinkMethod · 0.45
resolveMethod · 0.45
isDirectoryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…