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

Function realpathSync

lib/fs.js:3234–3367  ·  view source on GitHub ↗

* Returns the resolved pathname. * @param {string | Buffer | URL} p * @param {string | { encoding?: string | null; }} [options] * @returns {string | Buffer}

(p, options)

Source from the content-addressed store, hash-verified

3232 * @returns {string | Buffer}
3233 */
3234function realpathSync(p, options) {
3235 const h = vfsState.handlers;
3236 if (h !== null) {
3237 const result = h.realpathSync(p, options);
3238 if (result !== undefined) return result;
3239 }
3240 options = getOptions(options);
3241 p = toPathIfFileURL(p);
3242 if (typeof p !== 'string') {
3243 p += '';
3244 }
3245 validatePath(p);
3246 p = pathModule.resolve(p);
3247
3248 const cache = options[realpathCacheKey];
3249 const maybeCachedResult = cache?.get(p);
3250 if (maybeCachedResult) {
3251 return maybeCachedResult;
3252 }
3253
3254 const seenLinks = new SafeMap();
3255 const knownHard = new SafeSet();
3256 const original = p;
3257
3258 // Current character position in p
3259 let pos;
3260 // The partial path so far, including a trailing slash if any
3261 let current;
3262 // The partial path without a trailing slash (except when pointing at a root)
3263 let base;
3264 // The partial path scanned in the previous round, with slash
3265 let previous;
3266
3267 // Skip over roots
3268 current = base = splitRoot(p);
3269 pos = current.length;
3270
3271 // On windows, check that the root exists. On unix there is no need.
3272 if (isWindows) {
3273 const out = binding.lstat(base, false, undefined, true /* throwIfNoEntry */);
3274 if (out === undefined) {
3275 return;
3276 }
3277 knownHard.add(base);
3278 }
3279
3280 // Walk down the path, swapping out linked path parts for their real
3281 // values
3282 // NB: p.length changes.
3283 while (pos < p.length) {
3284 // find the next part
3285 const result = nextPart(p, pos);
3286 previous = current;
3287 if (result === -1) {
3288 const last = StringPrototypeSlice(p, pos);
3289 current += last;
3290 base = previous + last;
3291 pos = p.length;

Callers 15

transformProjectRootFunction · 0.50
test_relative_input_cwdFunction · 0.50
test_deep_symlink_mixFunction · 0.50
test_non_symlinksFunction · 0.50
test_upone_actualFunction · 0.50
test_up_multipleFunction · 0.50

Calls 13

toPathIfFileURLFunction · 0.85
isFileTypeFunction · 0.85
encodeRealpathResultFunction · 0.85
getMethod · 0.65
addMethod · 0.65
hasMethod · 0.65
getOptionsFunction · 0.50
realpathSyncMethod · 0.45
resolveMethod · 0.45
lstatMethod · 0.45
setMethod · 0.45
statMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…