Skip to content

Commit fb67c46

Browse files
Merge branch 'master' into develop
# Conflicts: # pom.xml
2 parents 4b6c348 + ea8356f commit fb67c46

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
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);

src/main/java/org/cryptomator/cryptofs/fh/ExceptionsDuringWrite.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@
1414
@OpenFileScoped
1515
public class ExceptionsDuringWrite {
1616

17-
private final List<IOException> exceptions = new ArrayList<>();
17+
private final IOException e = new IOException("Exceptions occured while writing");
1818

1919
@Inject
2020
public ExceptionsDuringWrite() {
2121
}
2222

2323
public synchronized void add(IOException e) {
24-
exceptions.add(e);
24+
e.addSuppressed(e);
2525
}
2626

2727
public synchronized void throwIfPresent() throws IOException {
28-
if (!exceptions.isEmpty()) {
29-
IOException e = new IOException("Exceptions occured while writing");
30-
exceptions.forEach(e::addSuppressed);
28+
if (e.getSuppressed().length > 0) {
29+
e.fillInStackTrace();
3130
throw e;
3231
}
3332
}

0 commit comments

Comments
 (0)