Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cryptomator.cryptofs.ch;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import org.cryptomator.cryptofs.CryptoFileSystemStats;
import org.cryptomator.cryptofs.EffectiveOpenOptions;
Expand Down Expand Up @@ -245,7 +246,8 @@ private void flush() throws IOException {
*
* @throws IOException
*/
private void persistLastModified() throws IOException {
@VisibleForTesting
void persistLastModified() throws IOException {
FileTime lastModifiedTime = isWritable() ? FileTime.from(lastModified.get()) : null;
FileTime lastAccessTime = FileTime.from(Instant.now());
var p = currentFilePath.get();
Expand Down Expand Up @@ -322,6 +324,7 @@ long beginOfChunk(long cleartextPos) {
protected void implCloseChannel() throws IOException {
try {
flush();
ciphertextFileChannel.force(true);
try {
persistLastModified();
} catch (NoSuchFileException nsfe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -240,6 +242,17 @@ public void testCloseTriggersCloseListener() throws IOException {
verify(closeListener).closed(inTest);
}

@Test
@DisplayName("On close, first flush channel, then persist lastModified")
public void testCloseFlushBeforePersist() throws IOException {
var inSpy = spy(inTest);
inSpy.implCloseChannel();

var ordering = inOrder(inSpy, ciphertextFileChannel);
ordering.verify(ciphertextFileChannel).force(true);
ordering.verify(inSpy).persistLastModified();
}

@Test
public void testCloseUpdatesLastModifiedTimeIfWriteable() throws IOException {
when(options.writable()).thenReturn(true);
Expand Down