Improve message cache behavior in case of io error

This commit is contained in:
AsamK 2023-09-23 12:25:30 +02:00
parent 0bdc400a30
commit 67747253e8

View file

@ -51,13 +51,21 @@ public class MessageCache {
public CachedMessage cacheMessage(SignalServiceEnvelope envelope, RecipientId recipientId) {
final var now = System.currentTimeMillis();
File cacheFile;
try {
cacheFile = getMessageCacheFile(recipientId, now, envelope.getTimestamp());
} catch (IOException e) {
logger.warn("Failed to create recipient folder in disk cache: {}", e.getMessage());
throw new RuntimeException(e);
}
final var cachedMessage = new CachedMessage(cacheFile, envelope);
try {
var cacheFile = getMessageCacheFile(recipientId, now, envelope.getTimestamp());
MessageCacheUtils.storeEnvelope(envelope, cacheFile);
return new CachedMessage(cacheFile, envelope);
return cachedMessage;
} catch (IOException e) {
logger.warn("Failed to store encrypted message in disk cache, ignoring: {}", e.getMessage());
return null;
return cachedMessage;
}
}