1
0
Fork 1

Do not rename the file to uuid.ext after download

(cherry picked from commit 5789814789f139c00ecc8b9638d696d9a866ce6b)
This commit is contained in:
Torsten Flammiger 2023-12-15 14:18:53 +01:00 committed by 12aw
parent 203088a053
commit b0b956eb86

View file

@ -214,33 +214,34 @@ public class HttpDownloadConnection implements Transferable {
if (message.getEncryption() == Message.ENCRYPTION_PGP) { if (message.getEncryption() == Message.ENCRYPTION_PGP) {
notify = message.getConversation().getAccount().getPgpDecryptionService().decrypt(message, notify); notify = message.getConversation().getAccount().getPgpDecryptionService().decrypt(message, notify);
} }
DownloadableFile file;
final DownloadableFile tmp = mXmppConnectionService.getFileBackend().getFile(message); DownloadableFile file = mXmppConnectionService.getFileBackend().getFile(message);
final String extension = MimeUtils.extractRelevantExtension(tmp.getName()); message.setRelativeFilePath(file.getAbsolutePath());
try {
mXmppConnectionService.getFileBackend().setupRelativeFilePath(message, new FileInputStream(tmp), extension); boolean isDeleted = false;
file = mXmppConnectionService.getFileBackend().getFile(message); for(Cid cid : message.getFileParams().getCids()) {
boolean didRename = tmp.renameTo(file); if(mXmppConnectionService.databaseBackend.isBlockedMedia(cid)) {
if (!didRename) throw new IOException("rename failed"); message.setDeleted(true);
} catch (final IOException e) { isDeleted = true;
Log.w(Config.LOGTAG, "Failed to rename downloaded file: " + e); file.delete(); // TODO: use java.nio
file = tmp; break;
message.setRelativeFilePath(file.getAbsolutePath()); }
} catch (final XmppConnectionService.BlockedMediaException e) {
file = tmp;
tmp.delete();
message.setDeleted(true);
} }
message.setTransferable(null); message.setTransferable(null);
if (cb != null) cb.accept(file); if (cb != null && !isDeleted) cb.accept(file);
mXmppConnectionService.updateMessage(message); mXmppConnectionService.updateMessage(message);
mHttpConnectionManager.finishConnection(this); mHttpConnectionManager.finishConnection(this);
final boolean notifyAfterScan = notify;
mXmppConnectionService.getFileBackend().updateMediaScanner(file, () -> { if(!isDeleted) {
if (notifyAfterScan) { final boolean notifyAfterScan = notify;
mXmppConnectionService.getNotificationService().push(message); mXmppConnectionService.getFileBackend().updateMediaScanner(file, () -> {
} if (notifyAfterScan) {
}); mXmppConnectionService.getNotificationService().push(message);
}
});
}
} }
private void decryptIfNeeded() throws IOException { private void decryptIfNeeded() throws IOException {