|
@@ -1,4 +1,5 @@
|
|
|
import { Buffer } from 'buffer';
|
|
|
+import { constants } from 'fs';
|
|
|
import * as path from 'path';
|
|
|
import * as util from 'util';
|
|
|
import type * as Crypto from 'crypto';
|
|
@@ -67,18 +68,22 @@ const gid = process.getgid?.() ?? 0;
|
|
|
|
|
|
const fakeTime = new Date();
|
|
|
|
|
|
-const asarStatsToFsStats = function (stats: NodeJS.AsarFileStat) {
|
|
|
- const { Stats, constants } = require('fs');
|
|
|
+enum AsarFileType {
|
|
|
+ kFile = (constants as any).UV_DIRENT_FILE,
|
|
|
+ kDirectory = (constants as any).UV_DIRENT_DIR,
|
|
|
+ kLink = (constants as any).UV_DIRENT_LINK,
|
|
|
+}
|
|
|
|
|
|
- let mode = constants.S_IROTH ^ constants.S_IRGRP ^ constants.S_IRUSR ^ constants.S_IWUSR;
|
|
|
+const fileTypeToMode = new Map<AsarFileType, number>([
|
|
|
+ [AsarFileType.kFile, constants.S_IFREG],
|
|
|
+ [AsarFileType.kDirectory, constants.S_IFDIR],
|
|
|
+ [AsarFileType.kLink, constants.S_IFLNK]
|
|
|
+]);
|
|
|
|
|
|
- if (stats.isFile) {
|
|
|
- mode ^= constants.S_IFREG;
|
|
|
- } else if (stats.isDirectory) {
|
|
|
- mode ^= constants.S_IFDIR;
|
|
|
- } else if (stats.isLink) {
|
|
|
- mode ^= constants.S_IFLNK;
|
|
|
- }
|
|
|
+const asarStatsToFsStats = function (stats: NodeJS.AsarFileStat) {
|
|
|
+ const { Stats } = require('fs');
|
|
|
+
|
|
|
+ const mode = constants.S_IROTH | constants.S_IRGRP | constants.S_IRUSR | constants.S_IWUSR | fileTypeToMode.get(stats.type)!;
|
|
|
|
|
|
return new Stats(
|
|
|
1, // dev
|
|
@@ -241,7 +246,6 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|
|
const logASARAccess = (asarPath: string, filePath: string, offset: number) => {
|
|
|
if (!process.env.ELECTRON_LOG_ASAR_READS) return;
|
|
|
if (!logFDs.has(asarPath)) {
|
|
|
- const path = require('path');
|
|
|
const logFilename = `${path.basename(asarPath, '.asar')}-access-log.txt`;
|
|
|
const logPath = path.join(require('os').tmpdir(), logFilename);
|
|
|
logFDs.set(asarPath, fs.openSync(logPath, 'a'));
|
|
@@ -657,13 +661,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|
|
nextTick(callback!, [error]);
|
|
|
return;
|
|
|
}
|
|
|
- if (stats.isFile) {
|
|
|
- dirents.push(new fs.Dirent(file, fs.constants.UV_DIRENT_FILE));
|
|
|
- } else if (stats.isDirectory) {
|
|
|
- dirents.push(new fs.Dirent(file, fs.constants.UV_DIRENT_DIR));
|
|
|
- } else if (stats.isLink) {
|
|
|
- dirents.push(new fs.Dirent(file, fs.constants.UV_DIRENT_LINK));
|
|
|
- }
|
|
|
+ dirents.push(new fs.Dirent(file, stats.type));
|
|
|
}
|
|
|
nextTick(callback!, [null, dirents]);
|
|
|
return;
|
|
@@ -700,13 +698,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|
|
if (!stats) {
|
|
|
throw createError(AsarError.NOT_FOUND, { asarPath, filePath: childPath });
|
|
|
}
|
|
|
- if (stats.isFile) {
|
|
|
- dirents.push(new fs.Dirent(file, fs.constants.UV_DIRENT_FILE));
|
|
|
- } else if (stats.isDirectory) {
|
|
|
- dirents.push(new fs.Dirent(file, fs.constants.UV_DIRENT_DIR));
|
|
|
- } else if (stats.isLink) {
|
|
|
- dirents.push(new fs.Dirent(file, fs.constants.UV_DIRENT_LINK));
|
|
|
- }
|
|
|
+ dirents.push(new fs.Dirent(file, stats.type));
|
|
|
}
|
|
|
return dirents;
|
|
|
}
|
|
@@ -757,7 +749,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|
|
const stats = archive.stat(filePath);
|
|
|
if (!stats) return -34;
|
|
|
|
|
|
- return (stats.isDirectory) ? 1 : 0;
|
|
|
+ return (stats.type === AsarFileType.kDirectory) ? 1 : 0;
|
|
|
};
|
|
|
|
|
|
// Calling mkdir for directory inside asar archive should throw ENOTDIR
|