Repository navigation
ADFA-7438 Write cogo-plugin.jar and init.gradle only when they differ from the asset - #2360
Open
davidschachterADFA wants to merge 5 commits into
Open
davidschachterADFA wants to merge 5 commits into
davidschachterADFA wants to merge 5 commits into
Conversation
One write path for extracted files: temp sibling, fsync, atomic rename. The tooling jar keeps its stamp logic; it only gains the fsync, and a failed rename now removes its .part. AssetSource replaces ToolingJarSource. No call site of cogo-plugin.jar or init.gradle changes yet. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Covers first start, restart with no write (mtime and open count), app update, truncated, longer and flipped-byte files, a reader during the write, and failing sources. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… from the asset Each start deleted both files and wrote them again, leaving a window where a build could find them missing, and wrote about 265 KB to flash. They now go through ExtractedFile.syncIfChanged: compared with the APK asset byte for byte, replaced through a temp file and atomic rename only when different. readInitScript is gone; the init script is copied as bytes. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
A stamp alone cannot see a jar truncated after extraction. The stamp file now holds versionName:lastUpdateTime;length and isToolingJarCurrent requires the jar's current length to match, so a truncated jar re-extracts. A stamp from the current release has no length and is treated as not current: the jar re-extracts once (an app update already changes lastUpdateTime, so this coincides with the upgrade). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
From the independent review: an inflating asset stream may return a few bytes per read, so the comparison and the copy are now tested against such a stream. Also tested: files of exactly one and two buffers, an empty file, files one byte off a buffer boundary, and a stale .part left by a killed process. The lock comment now names both callers and the lock order. No behaviour change. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ADFA-7438
Problem. At every start,
ToolsManager.initdeletedcogo-plugin.jarandinit.gradleand wrote them again. A Gradle build that opened either file in that window found it missing, and every start wrote about 265 KB to flash for nothing.Fix. A new package-private class,
ExtractedFile, keeps a file equal to its APK asset:syncIfChangedstreams the file against the asset and stops at the first difference. It writes only when the file is missing or differs.<name>.part, is fsynced, then renamed over the target, so a reader sees the old complete file or the new one, never a missing or partial file. The temp file is removed on every failure path.cogo-plugin.jarandinit.gradlenow go throughsyncIfChanged.init.gradleis copied as bytes; the old String round trip (readInitScript) is gone.ExtractedFile.replaceAtomically, which adds the fsync. Its stamp file also records the jar's length, so a jar truncated after extraction re-extracts.The two SQLite debugger AARs move onto
syncIfChangedin a follow-up PR once #2262 merges.Behaviour notes.
lastUpdateTimeanyway, so this coincides with the upgrade.Tests (
:common:testV8DebugUnitTest, managers package): ExtractedFileTest 16 and ToolsManagerToolingJarTest 16, all passing..part.Checked on a Galaxy J7 (Android 9; the J7's baseline debug build with only the changed
classes2.dexswapped in, so the bundled assets stayed identical):;48496870, its size.part:app:assembleDebugof an Empty Activity project.partNot in this PR. The same delete-then-copy window exists in
extractLogSender(the LogSender AAR, which Gradle also reads),extractColorSchemeandResourceUtils.copyFileFromAssets.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Code Reviewer: Code Reviewer couldn't review this pull request
The pull request author does not have access to AI for the associated Atlassian organization.