fix: override fs.realpathSync.native and fs.realpath.native (#14031)
* fix: override fs.realpathSync.native and fs.realpath.native * spec: test new native functions
This commit is contained in:
parent
8dae1c8447
commit
b785f45852
2 changed files with 228 additions and 82 deletions
|
@ -332,43 +332,68 @@
|
|||
const {realpathSync} = fs
|
||||
fs.realpathSync = function (p) {
|
||||
const [isAsar, asarPath, filePath] = splitPath(p)
|
||||
if (!isAsar) {
|
||||
return realpathSync.apply(this, arguments)
|
||||
}
|
||||
if (!isAsar) return realpathSync.apply(this, arguments)
|
||||
|
||||
const archive = getOrCreateArchive(asarPath)
|
||||
if (!archive) {
|
||||
invalidArchiveError(asarPath)
|
||||
}
|
||||
if (!archive) return invalidArchiveError(asarPath)
|
||||
|
||||
const real = archive.realpath(filePath)
|
||||
if (real === false) {
|
||||
notFoundError(asarPath, filePath)
|
||||
}
|
||||
if (real === false) notFoundError(asarPath, filePath)
|
||||
|
||||
return path.join(realpathSync(asarPath), real)
|
||||
}
|
||||
|
||||
fs.realpathSync.native = function (p) {
|
||||
const [isAsar, asarPath, filePath] = splitPath(p)
|
||||
if (!isAsar) return realpathSync.native.apply(this, arguments)
|
||||
|
||||
const archive = getOrCreateArchive(asarPath)
|
||||
if (!archive) return invalidArchiveError(asarPath)
|
||||
|
||||
const real = archive.realpath(filePath)
|
||||
if (real === false) notFoundError(asarPath, filePath)
|
||||
|
||||
return path.join(realpathSync.native(asarPath), real)
|
||||
}
|
||||
|
||||
const {realpath} = fs
|
||||
fs.realpath = function (p, cache, callback) {
|
||||
const [isAsar, asarPath, filePath] = splitPath(p)
|
||||
if (!isAsar) {
|
||||
return realpath.apply(this, arguments)
|
||||
}
|
||||
if (!isAsar) return realpath.apply(this, arguments)
|
||||
|
||||
if (typeof cache === 'function') {
|
||||
callback = cache
|
||||
cache = void 0
|
||||
}
|
||||
|
||||
const archive = getOrCreateArchive(asarPath)
|
||||
if (!archive) {
|
||||
return invalidArchiveError(asarPath, callback)
|
||||
}
|
||||
if (!archive) return invalidArchiveError(asarPath, callback)
|
||||
|
||||
const real = archive.realpath(filePath)
|
||||
if (real === false) {
|
||||
return notFoundError(asarPath, filePath, callback)
|
||||
if (real === false) return notFoundError(asarPath, filePath, callback)
|
||||
|
||||
return realpath(asarPath, (err, p) => {
|
||||
return (err) ? callback(err) : callback(null, path.join(p, real))
|
||||
})
|
||||
}
|
||||
|
||||
fs.realpath.native = function (p, cache, callback) {
|
||||
const [isAsar, asarPath, filePath] = splitPath(p)
|
||||
if (!isAsar) return realpath.native.apply(this, arguments)
|
||||
|
||||
if (typeof cache === 'function') {
|
||||
callback = cache
|
||||
cache = void 0
|
||||
}
|
||||
return realpath(asarPath, function (err, p) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
return callback(null, path.join(p, real))
|
||||
|
||||
const archive = getOrCreateArchive(asarPath)
|
||||
if (!archive) return invalidArchiveError(asarPath, callback)
|
||||
|
||||
const real = archive.realpath(filePath)
|
||||
if (real === false) return notFoundError(asarPath, filePath, callback)
|
||||
|
||||
return realpath.native(asarPath, (err, p) => {
|
||||
return (err) ? callback(err) : callback(null, path.join(p, real))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue