Improve file transfer resilience

This commit is contained in:
crschnick 2024-05-20 10:31:29 +00:00
parent 7c6906d86e
commit 07caa29262

View file

@ -95,8 +95,15 @@ public class FileBridge {
if (e.hasChanged()) {
event("Registering change for file " + TEMP.relativize(e.file) + " for editor entry " + e.getName());
e.registerChange();
var expectedSize = Files.size(e.file);
try (var in = Files.newInputStream(e.file)) {
e.writer.accept(in, (long) in.available());
var actualSize = (long) in.available();
if (expectedSize != actualSize) {
event("Expected file size " + expectedSize + " but got size " + actualSize + ". Ignoring change ...");
return;
}
e.writer.accept(in, actualSize);
}
}
} catch (Exception ex) {