Add asar-supported fs.accessSync implementation
This commit is contained in:
parent
3ad5504194
commit
30fbe92970
2 changed files with 53 additions and 0 deletions
|
@ -409,6 +409,36 @@
|
|||
})
|
||||
}
|
||||
|
||||
const {accessSync} = fs
|
||||
fs.accessSync = function (p, mode) {
|
||||
const [isAsar, asarPath, filePath] = splitPath(p)
|
||||
if (!isAsar) {
|
||||
return accessSync.apply(this, arguments)
|
||||
}
|
||||
if (mode == null) {
|
||||
mode = fs.constants.F_OK
|
||||
}
|
||||
const archive = getOrCreateArchive(asarPath)
|
||||
if (!archive) {
|
||||
invalidArchiveError(asarPath)
|
||||
}
|
||||
const info = archive.getFileInfo(filePath)
|
||||
if (!info) {
|
||||
notFoundError(asarPath, filePath)
|
||||
}
|
||||
if (info.unpacked) {
|
||||
const realPath = archive.copyFileOut(filePath)
|
||||
return fs.accessSync(realPath, mode)
|
||||
}
|
||||
const stats = getOrCreateArchive(asarPath).stat(filePath)
|
||||
if (!stats) {
|
||||
notFoundError(asarPath, filePath)
|
||||
}
|
||||
if (mode & fs.constants.W_OK) {
|
||||
accessError(asarPath, filePath)
|
||||
}
|
||||
}
|
||||
|
||||
const {readFile} = fs
|
||||
fs.readFile = function (p, options, callback) {
|
||||
const [isAsar, asarPath, filePath] = splitPath(p)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue