Skip to content

Commit fe4d250

Browse files
committed
feat: optimize safeRemoveDirectory by importing fs/promises directly and simplifying removal logic
1 parent 8243d2d commit fe4d250

File tree

1 file changed

+3
-5
lines changed
  • src/backend/storeManagers/hyperplay

1 file changed

+3
-5
lines changed

src/backend/storeManagers/hyperplay/utils.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ProjectMetaInterface } from '@valist/sdk/dist/typesShared'
2323
import getPartitionCookies from 'backend/utils/get_partition_cookies'
2424
import { DEV_PORTAL_URL } from 'common/constants'
2525
import { captureException } from '@sentry/electron'
26+
import { access, rm } from 'fs/promises'
2627

2728
export async function getHyperPlayStoreRelease(
2829
appName: string
@@ -452,16 +453,13 @@ export async function safeRemoveDirectory(
452453
// Log start of removal process
453454
logInfo(`Starting removal of directory ${directory}`, LogPrefix.HyperPlay)
454455

455-
// Import fs promises for async operations only when needed
456-
const fsPromises = await import('fs/promises')
457-
458456
for (let attempt = 1; attempt <= maxRetries; attempt++) {
459457
try {
460458
// Use different removal strategies based on expected size
461459
// For directories larger than threshold, use async removal to not block the main thread
462460
if (sizeThresholdMB > 250) {
463461
try {
464-
await fsPromises.rm(directory, {
462+
await rm(directory, {
465463
recursive: true,
466464
force: true,
467465
maxRetries: 3
@@ -481,7 +479,7 @@ export async function safeRemoveDirectory(
481479

482480
// Verify directory was actually removed
483481
try {
484-
await fsPromises.access(directory)
482+
await access(directory)
485483
// If we get here, directory still exists
486484
logWarning(
487485
`Failed to remove directory ${directory} on attempt ${attempt}/${maxRetries}, directory still exists`,

0 commit comments

Comments
 (0)