GenericCopyUtil improvements#4577
Conversation
a123ebc to
0cb5abf
Compare
There was a problem hiding this comment.
Pull request overview
This PR modernizes GenericCopyUtil by migrating it (and its tests) from Java to Kotlin, while improving copy robustness/performance via larger transfer quanta and batched progress callbacks. It also replaces deprecated JUnit @Theory-based tests with explicit Kotlin test cases and adds new coverage for cancellation and progress batching.
Changes:
- Replaced
GenericCopyUtilJava implementation with a Kotlin version usingFileChannel.transferTofor file-to-file copies and batched progress updates. - Replaced Java unit/instrumentation tests with Kotlin tests (no deprecated
@Theory), adding more scenarios (empty file, cancellation, batching). - Increased transfer buffer quantum (1MB) for OTG/DocumentFile paths and channel-based copies.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| app/src/main/java/com/amaze/filemanager/filesystem/files/GenericCopyUtil.kt | Kotlin rewrite; adds transferTo fast path + progress batching + 1MB transfer quantum. |
| app/src/main/java/com/amaze/filemanager/filesystem/files/GenericCopyUtil.java | Removes old Java implementation. |
| app/src/test/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilTest.kt | New Robolectric unit tests replacing @Theory, adding batching/cancellation coverage. |
| app/src/test/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilTest.java | Removes old Java unit tests. |
| app/src/androidTest/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilEspressoTest.kt | New instrumented tests in Kotlin, including batching/cancellation scenarios. |
| app/src/androidTest/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilEspressoTest.java | Removes old Java instrumented tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| while (position < size && !progressHandler.cancelled) { | ||
| val transferred = from.transferTo(position, DEFAULT_TRANSFER_QUANTUM.toLong(), to) | ||
| position += transferred | ||
| pendingProgress += transferred | ||
| if (pendingProgress >= PROGRESS_UPDATE_THRESHOLD) { | ||
| updatePosition.updatePosition(pendingProgress) | ||
| pendingProgress = 0L | ||
| } |
There was a problem hiding this comment.
FileChannel.transferTo() can legally return 0 even when position < size (e.g., platform/FS limitations). In the current loop this would leave position unchanged and can cause an infinite loop/hang. Add a guard for transferred <= 0 (break + fallback to the ByteBuffer path or throw an IOException) to guarantee progress.
app/src/main/java/com/amaze/filemanager/filesystem/files/GenericCopyUtil.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/amaze/filemanager/filesystem/files/GenericCopyUtil.kt
Outdated
Show resolved
Hide resolved
app/src/test/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilTest.kt
Outdated
Show resolved
Hide resolved
app/src/test/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilTest.kt
Outdated
Show resolved
Hide resolved
app/src/androidTest/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilEspressoTest.kt
Outdated
Show resolved
Hide resolved
app/src/androidTest/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilEspressoTest.kt
Outdated
Show resolved
Hide resolved
52dfe14 to
0368390
Compare
- Convert to Kotlin - More tests - Bigger buffer size for copy from/to OTG storage
0368390 to
df0d36d
Compare
Description
@Theoryin testsAutomatic tests
Manual tests
Build tasks success
Successfully running following tasks on local:
./gradlew assembledebug./gradlew spotlessCheck