Workaround tmp files disappearing

pull/207/head
M66B 3 years ago
parent 645c70775a
commit daf75f80df

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

Loading…
Cancel
Save