~singpolyma/cheogram-android

61b1eb2aa5892774d2e433fcdd62e424d25e0892 — Stephen Paul Weber 9 months ago a59b60d 2.11.0-1
Do not lose the file if the rename fails
M src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java => src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +4 -1
@@ 195,9 195,12 @@ public class HttpDownloadConnection implements Transferable {
        try {
            mXmppConnectionService.getFileBackend().setupRelativeFilePath(message, new FileInputStream(tmp), extension);
            file = mXmppConnectionService.getFileBackend().getFile(message);
            tmp.renameTo(file);
            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());
        }
        message.setTransferable(null);
        mXmppConnectionService.updateMessage(message);

M src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java => src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java +3 -1
@@ 133,9 133,11 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
                try {
                    xmppConnectionService.getFileBackend().setupRelativeFilePath(message, new FileInputStream(file), extension);
                    finalFile = xmppConnectionService.getFileBackend().getFile(message);
                    file.renameTo(finalFile);
                    boolean didRename = file.renameTo(finalFile);
                    if (!didRename) throw new IOException("rename failed");
                } catch (final IOException e) {
                    finalFile = file;
                    message.setRelativeFilePath(finalFile.getAbsolutePath());
                }

                xmppConnectionService.getFileBackend().updateFileParams(message, null, false);