Skip to content

Commit f42cf5f

Browse files
committed
perf(ipc): pass force: true to safeDelete for tmpdir files
Optimize safeDelete calls in IPC cleanup by passing { force: true } since IPC stub files are always in os.tmpdir()/.socket-ipc/. This skips unnecessary path validation checks that would otherwise: 1. Load os, path, and paths modules 2. Resolve tmpdir, cacache, and socketUserDir 3. Check each file path against all allowed directories This is especially beneficial in cleanupIpcStubs which processes multiple files in Promise.all(), where each file would trigger these checks independently without force: true.
1 parent eb2eb5f commit f42cf5f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ipc.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ export async function readIpcStub(stubPath: string): Promise<unknown> {
328328
// 5 minutes.
329329
const maxAgeMs = 5 * 60 * 1000
330330
if (ageMs > maxAgeMs) {
331-
// Clean up stale file.
332-
await safeDelete(stubPath).catch(() => {})
331+
// Clean up stale file. IPC stubs are always in tmpdir, so use force: true.
332+
await safeDelete(stubPath, { force: true }).catch(() => {})
333333
return null
334334
}
335335
return validated.data
@@ -395,7 +395,8 @@ export async function cleanupIpcStubs(appName: string): Promise<void> {
395395
}
396396

397397
if (isStale) {
398-
await safeDelete(filePath)
398+
// IPC stubs are always in tmpdir, so we can use force: true to skip path checks
399+
await safeDelete(filePath, { force: true })
399400
}
400401
} catch {
401402
// Ignore errors for individual files.

0 commit comments

Comments
 (0)