Skip to content

Commit eccecec

Browse files
fixes #67
1 parent 06685b0 commit eccecec

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/main/java/org/cryptomator/cryptofs/ch/CleartextFileChannel.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ public void force(boolean metaData) throws IOException {
208208
}
209209

210210
private void forceInternal(boolean metaData) throws IOException {
211-
if (isWritable()) {
212-
writeHeaderIfNeeded();
213-
chunkCache.invalidateAll(); // TODO performance: write chunks but keep them cached
214-
exceptionsDuringWrite.throwIfPresent();
215-
}
211+
flush();
216212
ciphertextFileChannel.force(metaData);
217213
if (metaData) {
218214
FileTime lastModifiedTime = isWritable() ? FileTime.from(lastModified.get()) : null;
@@ -221,6 +217,18 @@ private void forceInternal(boolean metaData) throws IOException {
221217
}
222218
}
223219

220+
/**
221+
* Writes in-memory contents to the ciphertext file
222+
* @throws IOException
223+
*/
224+
private void flush() throws IOException {
225+
if (isWritable()) {
226+
writeHeaderIfNeeded();
227+
chunkCache.invalidateAll(); // TODO performance: write chunks but keep them cached
228+
exceptionsDuringWrite.throwIfPresent();
229+
}
230+
}
231+
224232
@Override
225233
public MappedByteBuffer map(MapMode mode, long position, long size) {
226234
throw new UnsupportedOperationException();
@@ -285,7 +293,7 @@ long beginOfChunk(long cleartextPos) {
285293
@Override
286294
protected void implCloseChannel() throws IOException {
287295
try {
288-
forceInternal(true);
296+
flush();
289297
} finally {
290298
super.implCloseChannel();
291299
closeListener.closed(this);

0 commit comments

Comments
 (0)