MCPcopy
hub / github.com/webpack/webpack / lstatReadlinkAbsolute

Function lstatReadlinkAbsolute

lib/util/fs.js:701–732  ·  view source on GitHub ↗
(fs, p, callback)

Source from the content-addressed store, hash-verified

699 * @returns {void}
700 */
701const lstatReadlinkAbsolute = (fs, p, callback) => {
702 let i = 3;
703 const doReadLink = () => {
704 fs.readlink(p, (err, target) => {
705 if (err && --i > 0) {
706 // It might was just changed from symlink to file
707 // we retry 2 times to catch this case before throwing the error
708 return doStat();
709 }
710 if (err) return callback(err);
711 const value = /** @type {string} */ (target).toString();
712 callback(null, join(fs, dirname(fs, p), value));
713 });
714 };
715 const doStat = () => {
716 if ("lstat" in fs) {
717 return /** @type {NonNullable<InputFileSystem["lstat"]>} */ (fs.lstat)(
718 p,
719 (err, stats) => {
720 if (err) return callback(err);
721 if (/** @type {IStats} */ (stats).isSymbolicLink()) {
722 return doReadLink();
723 }
724 callback(null, stats);
725 }
726 );
727 }
728 return fs.stat(p, callback);
729 };
730 if ("lstat" in fs) return doStat();
731 doReadLink();
732};
733
734/**
735 * Checks whether this object is absolute.

Callers 1

_readContextMethod · 0.85

Calls 2

doReadLinkFunction · 0.85
doStatFunction · 0.70

Tested by

no test coverage detected