-
Notifications
You must be signed in to change notification settings - Fork 35
Feature: First close file channel, then persist lastModified #228
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
34f1f80
fixes #205
infeo 6a3c352
first store updated lastModified in filesystem before writing it to u…
infeo 9fc9780
improve unit tests
infeo ae742d1
always persist lastModified
infeo 608ff17
Merge branch 'develop' into feature/205-close-before-lastModifiedPersist
infeo df785eb
fix unit test
infeo ecca2a6
Merge branch 'develop' into feature/205-close-before-lastModifiedPersist
infeo e247a2e
strech the finally methods over 3 methods
infeo 6757801
use helper function to execute all close actions
infeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
4 changes: 1 addition & 3 deletions
4
src/main/java/org/cryptomator/cryptofs/ch/ChannelCloseListener.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,9 @@ | ||
| package org.cryptomator.cryptofs.ch; | ||
|
|
||
|
|
||
| import java.io.IOException; | ||
|
|
||
| @FunctionalInterface | ||
| public interface ChannelCloseListener { | ||
|
|
||
| void closed(CleartextFileChannel channel) throws IOException; | ||
| void closed(CleartextFileChannel channel); | ||
|
|
||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,7 +233,8 @@ private void forceInternal(boolean metaData) throws IOException { | |
| * | ||
| * @throws IOException | ||
| */ | ||
| private void flush() throws IOException { | ||
| @VisibleForTesting | ||
| void flush() throws IOException { | ||
|
Comment on lines
+238
to
+239
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarified testing intent and enhanced data integrity during channel closure. Would you like me to help in adding or enhancing the unit tests to cover these new scenarios? Also applies to: 331-342 |
||
| if (isWritable()) { | ||
| writeHeaderIfNeeded(); | ||
| chunkCache.flush(); | ||
|
|
@@ -324,18 +325,31 @@ long beginOfChunk(long cleartextPos) { | |
| protected void implCloseChannel() throws IOException { | ||
| try { | ||
| flush(); | ||
| ciphertextFileChannel.force(true); | ||
| } finally { | ||
| implCloseChannelFinally1(); | ||
| } | ||
| } | ||
|
|
||
| private void implCloseChannelFinally1() throws IOException { | ||
| try { | ||
| super.implCloseChannel(); | ||
| } finally { | ||
| closeListener.closed(this); | ||
| implCloseChannelFinally2(); | ||
| } | ||
| } | ||
|
|
||
| private void implCloseChannelFinally2() throws IOException { | ||
| try { | ||
| ciphertextFileChannel.close(); | ||
| } finally { | ||
| try { | ||
| persistLastModified(); | ||
| } catch (NoSuchFileException nsfe) { | ||
| //no-op, see https://github.com/cryptomator/cryptofs/issues/169 | ||
| } catch (IOException e) { | ||
| //only best effort attempt | ||
| LOG.warn("Failed to persist last modified timestamp for encrypted file: {}", e.getMessage()); | ||
| } | ||
| } finally { | ||
| super.implCloseChannel(); | ||
| closeListener.closed(this); | ||
| } | ||
| } | ||
| } | ||
infeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.