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