Skip to content

feat: optimize cleanup logic and fix static resource bloat & fd leaks#598

Merged
sunnylqm merged 1 commit into
masterfrom
feat/optimize-cleanup-and-resource-copy
Jul 2, 2026
Merged

feat: optimize cleanup logic and fix static resource bloat & fd leaks#598
sunnylqm merged 1 commit into
masterfrom
feat/optimize-cleanup-and-resource-copy

Conversation

@sunnylqm

@sunnylqm sunnylqm commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This PR optimizes the hot update cleanup logic and fixes critical resource copying bugs on HarmonyOS:

Changes

  1. Fix Static Resource Bloat (HarmonyOS): Passed the view (mediaBuffer) instead of the underlying ArrayBuffer (mediaBuffer.buffer) when writing media resources. This prevents writing excessive raw buffer bytes to the sandbox files.
  2. Fix FD Leak (HarmonyOS): Wrapped the raw FD acquisition/resource copy inside a try...finally block to ensure resourceManager.closeRawFd is always called to release file descriptors.
  3. Optimize Old Version Clean Up (All Platforms): Reduced the retention period for obsolete hot-update version directories from 7 days to 3 days across Android, iOS, and HarmonyOS.
  4. Delete Downloaded Archive Immediately (Android): Aligned Android with iOS/HarmonyOS by deleting downloaded .ppk/.patch files immediately after successful decompression/patching rather than waiting for the old package clean-up job.

All core unit tests and lints pass.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup after update downloads and patch application, reducing leftover temporary archive files.
    • Made file cleanup more resilient so cleanup issues won’t interrupt the update process.
    • Updated retention handling so older update files are cleared more aggressively, helping keep storage usage lower.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cce08583-0617-44bc-b33b-bb48bd238b9d

📥 Commits

Reviewing files that changed from the base of the PR and between 336b6ab and 052da8e.

📒 Files selected for processing (4)
  • android/src/main/java/cn/reactnative/modules/update/DownloadTask.java
  • harmony/pushy/src/main/ets/DownloadTask.ts
  • harmony/pushy/src/main/ets/UpdateContext.ts
  • ios/RCTPushy/RCTPushy.mm

📝 Walkthrough

Walkthrough

Cleanup logic across Android, HarmonyOS, and iOS platforms is updated: downloaded/temporary archive files are now deleted after patch operations complete, retention window for old entry cleanup is reduced from 7 to 3 days, and HarmonyOS resource-copy logic is refactored for reliable file descriptor closing.

Changes

Temp file cleanup and retention window changes

Layer / File(s) Summary
Android temp file deletion and cleanup retention
android/src/main/java/cn/reactnative/modules/update/DownloadTask.java
doFullPatch() and doPatchFromApk() now delete params.targetFile after completing their operations; doCleanUp() deletes the target file before cleanup and reduces cleanupOldEntries retention from 7 to 3 days.
HarmonyOS temp file deletion and resource copy refactor
harmony/pushy/src/main/ets/DownloadTask.ts
doFullPatch, doPatchFromApp, and doPatchFromPpk wrap deletion of params.targetFile in try/catch with error logging; copyFromResource is refactored to use writeFileContent for media targets and try/finally FD closing for non-media targets; doCleanUp reduces retention to 3 days.
UpdateContext and iOS retention window update
harmony/pushy/src/main/ets/UpdateContext.ts, ios/RCTPushy/RCTPushy.mm
Both UpdateContext.cleanUp() and clearInvalidFiles change the retention argument passed to their respective cleanup functions from 7 to 3 days.

Estimated code review effort: 2 (Simple) | ~12 minutes

Poem

A rabbit hops through code so tidy,
Sweeping temp files, quick and speedy.
Seven days shrunk down to three,
Cleaner burrows, wild and free.
Patch, unlink, close the door —
Tidy warrens, nothing more! 🐇

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/optimize-cleanup-and-resource-copy

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

harmony/pushy/src/main/ets/DownloadTask.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: .eslintrc.js » @react-native/eslint-config#overrides[4]:
Environment key "jest/globals" is unknown

at /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2079:23
at Array.forEach (<anonymous>)
at ConfigValidator.validateEnvironment (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2073:34)
at ConfigValidator.validateConfigArray (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2223:18)
at CascadingConfigArrayFactory._finalizeConfigArray (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3985:23)
at CascadingConfigArrayFactory.getConfigArrayForFile (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3791:21)
at FileEnumerator._iterateFilesWithFile (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:368:43)
at FileEnumerator._iterateFiles (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:349:25)
at FileEnumerator.iterateFiles (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:299:59)
at iterateFiles.next (<anonymous>)
harmony/pushy/src/main/ets/UpdateContext.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: .eslintrc.js » @react-native/eslint-config#overrides[4]:
Environment key "jest/globals" is unknown

at /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2079:23
at Array.forEach (<anonymous>)
at ConfigValidator.validateEnvironment (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2073:34)
at ConfigValidator.validateConfigArray (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2223:18)
at CascadingConfigArrayFactory._finalizeConfigArray (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3985:23)
at CascadingConfigArrayFactory.getConfigArrayForFile (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3791:21)
at FileEnumerator._iterateFilesWithFile (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:368:43)
at FileEnumerator._iterateFiles (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:349:25)
at FileEnumerator.iterateFiles (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:299:59)
at iterateFiles.next (<anonymous>)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sunnylqm sunnylqm merged commit 37fa549 into master Jul 2, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant