refactor: use Map instead of Object for better semantics (#25982)

This commit is contained in:
Milan Burda 2020-10-19 02:24:51 +02:00 committed by GitHub
parent eca53aaaf1
commit 321395d96e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 34 deletions

View file

@ -216,16 +216,16 @@ const makePromiseFunction = function (orig: Function, pathArgumentIndex: number)
// Override fs APIs.
export const wrapFsWithAsar = (fs: Record<string, any>) => {
const logFDs: Record<string, number> = {};
const logFDs = new Map<string, number>();
const logASARAccess = (asarPath: string, filePath: string, offset: number) => {
if (!process.env.ELECTRON_LOG_ASAR_READS) return;
if (!logFDs[asarPath]) {
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[asarPath] = fs.openSync(logPath, 'a');
logFDs.set(asarPath, fs.openSync(logPath, 'a'));
}
fs.writeSync(logFDs[asarPath], `${offset}: ${filePath}\n`);
fs.writeSync(logFDs.get(asarPath), `${offset}: ${filePath}\n`);
};
const { lstatSync } = fs;