fix: make asarStatsToFsStats nherit from fs.stats (#14041)
This commit is contained in:
parent
b5bfd9867b
commit
69caea38c1
1 changed files with 28 additions and 35 deletions
|
@ -67,47 +67,40 @@
|
||||||
let nextInode = 0
|
let nextInode = 0
|
||||||
|
|
||||||
const uid = process.getuid != null ? process.getuid() : 0
|
const uid = process.getuid != null ? process.getuid() : 0
|
||||||
|
|
||||||
const gid = process.getgid != null ? process.getgid() : 0
|
const gid = process.getgid != null ? process.getgid() : 0
|
||||||
|
|
||||||
const fakeTime = new Date()
|
const fakeTime = new Date()
|
||||||
|
const msec = (date) => (date || fakeTime).getTime()
|
||||||
|
|
||||||
const asarStatsToFsStats = function (stats) {
|
const asarStatsToFsStats = function (stats) {
|
||||||
return {
|
const {Stats, constants} = require('fs')
|
||||||
dev: 1,
|
|
||||||
ino: ++nextInode,
|
let mode = constants.S_IROTH ^ constants.S_IRGRP ^ constants.S_IRUSR ^ constants.S_IWUSR
|
||||||
mode: 33188,
|
|
||||||
nlink: 1,
|
if (stats.isFile) {
|
||||||
uid: uid,
|
mode ^= constants.S_IFREG
|
||||||
gid: gid,
|
} else if (stats.isDirectory) {
|
||||||
rdev: 0,
|
mode ^= constants.S_IFDIR
|
||||||
atime: stats.atime || fakeTime,
|
} else if (stats.isLink) {
|
||||||
birthtime: stats.birthtime || fakeTime,
|
mode ^= constants.S_IFLNK
|
||||||
mtime: stats.mtime || fakeTime,
|
|
||||||
ctime: stats.ctime || fakeTime,
|
|
||||||
size: stats.size,
|
|
||||||
isFile: function () {
|
|
||||||
return stats.isFile
|
|
||||||
},
|
|
||||||
isDirectory: function () {
|
|
||||||
return stats.isDirectory
|
|
||||||
},
|
|
||||||
isSymbolicLink: function () {
|
|
||||||
return stats.isLink
|
|
||||||
},
|
|
||||||
isBlockDevice: function () {
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
isCharacterDevice: function () {
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
isFIFO: function () {
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
isSocket: function () {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Stats(
|
||||||
|
1, // dev
|
||||||
|
mode, // mode
|
||||||
|
1, // nlink
|
||||||
|
uid,
|
||||||
|
gid,
|
||||||
|
0, // rdev
|
||||||
|
undefined, // blksize
|
||||||
|
++nextInode, // ino
|
||||||
|
stats.size,
|
||||||
|
undefined, // blocks,
|
||||||
|
msec(stats.atime), // atim_msec
|
||||||
|
msec(stats.mtime), // mtim_msec
|
||||||
|
msec(stats.ctime), // ctim_msec
|
||||||
|
msec(stats.birthtime) // birthtim_msec
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a ENOENT error.
|
// Create a ENOENT error.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue