Skip to content

Commit e38fa98

Browse files
committed
refactor(onnx): use safeReadFile for patch verification
Replace existsSync + fs.readFile with safeReadFile which safely handles missing files and errors by returning undefined. This simplifies the code and follows the codebase's safe file operation patterns.
1 parent da9e508 commit e38fa98

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/onnxruntime/scripts/build.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import path from 'node:path'
1717
import { fileURLToPath } from 'node:url'
1818

1919
import { WIN32 } from '@socketsecurity/lib/constants/platform'
20-
import { safeDelete } from '@socketsecurity/lib/fs'
20+
import { safeDelete, safeReadFile } from '@socketsecurity/lib/fs'
2121
import { getDefaultLogger } from '@socketsecurity/lib/logger'
2222
import { spawn } from '@socketsecurity/lib/spawn'
2323
import {
@@ -96,10 +96,10 @@ async function cloneOnnxSource() {
9696

9797
// Check if all patches have been applied.
9898
const allPatchesApplied = (await Promise.all(
99-
patches.map(async ({ path: filePath, marker }) =>
100-
existsSync(filePath) &&
101-
(await fs.readFile(filePath, 'utf-8')).includes(marker)
102-
)
99+
patches.map(async ({ path: filePath, marker }) => {
100+
const content = await safeReadFile(filePath, 'utf-8')
101+
return content?.includes(marker) ?? false
102+
})
103103
)).every(Boolean)
104104

105105
if (!allPatchesApplied) {

0 commit comments

Comments
 (0)