1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-02 13:14:39 +00:00

Workaround tmp files disappearing

This commit is contained in:
M66B 2022-04-30 18:30:05 +02:00
parent 645c70775a
commit daf75f80df

View file

@ -4432,18 +4432,23 @@ public class FragmentCompose extends FragmentBase {
resized = rotated;
}
File tmp = File.createTempFile("image", ".resized", context.getCacheDir());
File tmp = new File(file.getAbsolutePath() + ".tmp");
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(tmp))) {
resized.compress("image/jpeg".equals(attachment.type)
? Bitmap.CompressFormat.JPEG
: Bitmap.CompressFormat.PNG,
REDUCED_IMAGE_QUALITY, out);
Bitmap.CompressFormat format = ("image/jpeg".equals(attachment.type)
? Bitmap.CompressFormat.JPEG : Bitmap.CompressFormat.PNG);
if (!resized.compress(format, REDUCED_IMAGE_QUALITY, out))
throw new IOException("compress");
} catch (Throwable ex) {
Log.w(ex);
tmp.delete();
} finally {
resized.recycle();
}
file.delete();
tmp.renameTo(file);
if (tmp.exists() && tmp.length() > 0) {
file.delete();
tmp.renameTo(file);
}
DB db = DB.getInstance(context);
db.attachment().setDownloaded(attachment.id, file.length());