Skip to content

Commit

Permalink
Unnecessary function
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Oct 10, 2023
1 parent a95072f commit 57213eb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 37 deletions.
12 changes: 7 additions & 5 deletions src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
fsLstatExists
} from '@shockpkg/archive-files';

import {once} from './util';
import {Queue} from './queue';
import {Projector} from './projector';

Expand Down Expand Up @@ -506,15 +505,18 @@ export abstract class Bundle {
}>
) {
const r = {...options} as IBundleResourceOptions;
const st = once(stat);
let st;
if (!r.atime && r.atimeCopy) {
r.atime = (await st()).atime;
st = await stat();
r.atime = st.atime;
}
if (!r.mtime && r.mtimeCopy) {
r.mtime = (await st()).mtime;
st ??= await stat();
r.mtime = st.mtime;
}
if (typeof r.executable !== 'boolean' && r.executableCopy) {
r.executable = this._getResourceModeExecutable((await st()).mode);
st ??= await stat();
r.executable = this._getResourceModeExecutable(st.mode);
}
return r;
}
Expand Down
18 changes: 0 additions & 18 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,6 @@ import {inflateRaw} from 'node:zlib';

import {LAUNCHERS} from './launchers';

/**
* Create return value once.
*
* @param create Create function.
* @returns Returned value.
*/
export function once<T>(create: () => T): () => T {
let called = false;
let value: T;
return () => {
if (!called) {
value = create();
called = true;
}
return value;
};
}

/**
* Trim dot flash from head of path.
*
Expand Down
36 changes: 22 additions & 14 deletions src/util/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {readFile} from 'node:fs/promises';

import {Plist, Value, ValueDict, ValueString} from '@shockpkg/plist-dom';

import {once, launcher} from '../util';
import {launcher} from '../util';

const FAT_MAGIC = 0xcafebabe;
const MH_MAGIC = 0xfeedface;
Expand All @@ -15,16 +15,6 @@ const CPU_TYPE_POWERPC = 0x00000012;
const CPU_TYPE_I386 = 0x00000007;
// const CPU_TYPE_X86_64 = 0x01000007;

const launcherMappings = once(
() =>
new Map([
[CPU_TYPE_POWERPC, 'mac-app-ppc'],
// [CPU_TYPE_POWERPC64, 'mac-app-ppc64'],
[CPU_TYPE_I386, 'mac-app-i386']
// [CPU_TYPE_X86_64, 'mac-app-x86_64']
])
);

export interface IMachoType {
//
/**
Expand Down Expand Up @@ -239,9 +229,27 @@ export async function machoTypesFile(path: string) {
*/
export async function machoAppLauncherThin(type: Readonly<IMachoType>) {
const {cpuType} = type;
const id = launcherMappings().get(cpuType);
if (!id) {
throw new Error(`Unknown CPU type: 0x${cpuType.toString(16)}`);
let id = '';
switch (cpuType) {
case CPU_TYPE_POWERPC: {
id = 'mac-app-ppc';
break;
}
// case CPU_TYPE_POWERPC64: {
// id = 'mac-app-ppc64';
// break;
// }
case CPU_TYPE_I386: {
id = 'mac-app-i386';
break;
}
// case CPU_TYPE_X86_64: {
// id = 'mac-app-x86_64';
// break;
// }
default: {
throw new Error(`Unknown CPU type: 0x${cpuType.toString(16)}`);
}
}
return launcher(id);
}
Expand Down

0 comments on commit 57213eb

Please sign in to comment.