-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use truncate() of CleartextChannel when opening new Channel with TRUNCATE_EXISTING
#270
Conversation
WalkthroughThe pull request introduces changes to the file channel management in the Cryptomator CryptoFS library. The primary modification occurs in the Assessment against linked issues
Possibly related PRs
Suggested Labels
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java (1)
Line range hint
619-635
: LGTM! Consider documenting the sleep duration.The test changes improve reliability and execution time:
- Reduced repetitions from 50 to 15 maintains coverage while improving execution time
- Added sleep ensures proper testing of concurrent behavior
Consider adding a comment explaining why 1000ms sleep is needed:
+ // Sleep for 1s to ensure writing operation has time to proceed before truncation Thread.sleep(1000);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/org/cryptomator/cryptofs/fh/OpenCryptoFile.java
(1 hunks)src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java
(2 hunks)src/test/java/org/cryptomator/cryptofs/fh/OpenCryptoFileTest.java
(1 hunks)
🔇 Additional comments (2)
src/main/java/org/cryptomator/cryptofs/fh/OpenCryptoFile.java (1)
77-79
: LGTM! Clean implementation of file truncation.The implementation correctly uses
cleartextFileChannel.truncate(0)
whentruncateExisting
is set. The change is:
- Thread-safe due to the synchronized context
- Protected by proper null checks and cleanup in the finally block
- Aligned with the PR objective to use CleartextChannel's truncate method
src/test/java/org/cryptomator/cryptofs/fh/OpenCryptoFileTest.java (1)
96-109
: LGTM! Test accurately verifies the new truncation behavior.The test has been properly updated to:
- Verify that
truncate(0)
is called on the cleartextChannel- Use clear and descriptive test name
- Set up proper mocking of dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, did you spot it in the failed CI run?
src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/cryptomator/cryptofs/fh/OpenCryptoFileTest.java
Outdated
Show resolved
Hide resolved
yes. I worked on a completely different feature (FileNameDecryptor) and was tempted to declare the failing build as a fluke. Luckily i decided to investigate the issue^^ We have tests for a reason! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/test/java/org/cryptomator/cryptofs/fh/OpenCryptoFileTest.java (1)
97-103
: Consider extracting mock setup to a helper method.The mock setup for channel components is repeated in multiple test methods. Consider extracting it to a helper method to improve test readability and maintainability.
+ private void setupChannelMocks(CleartextFileChannel cleartextChannel) { + Mockito.when(openCryptoFileComponent.newChannelComponent()).thenReturn(channelComponentFactory); + Mockito.when(channelComponentFactory.create(any(), any(), any())).thenReturn(channelComponent); + Mockito.when(channelComponent.channel()).thenReturn(cleartextChannel); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java
(3 hunks)src/test/java/org/cryptomator/cryptofs/fh/OpenCryptoFileTest.java
(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Analyse
- GitHub Check: Build and Test
🔇 Additional comments (2)
src/test/java/org/cryptomator/cryptofs/fh/OpenCryptoFileTest.java (2)
73-73
: LGTM! Constructor changes are consistent.The removal of the
chunkCache
parameter fromOpenCryptoFile
constructor calls is applied consistently across all test methods.Also applies to: 84-84, 104-104, 116-116, 200-200
94-107
: LGTM! Test correctly verifies truncate behavior.The test has been properly updated to verify that
truncate(0)
is called on thecleartextChannel
when opening withTRUNCATE_EXISTING
option. The mock setup and verification are comprehensive.
This PR fixes #269.
Instead of writing an "optimized", but wrong truncate block, we can simply use
CleartextChannel.truncate(0)
when opening a new file. Benefit of this method: It is already tested! And since it is synchronized and also creating a new file channel is synchronized, we can be sure that side calls cannot interfere.