Stop downloading attachments on error

This commit is contained in:
M66B 2019-01-17 10:24:36 +00:00
parent 3b06c3d027
commit 7dc4f6ecf3
2 changed files with 6 additions and 3 deletions

View File

@ -627,11 +627,11 @@ public class MessageHelper {
return result;
}
void downloadAttachment(Context context, DB db, long id, int sequence) throws IOException {
boolean downloadAttachment(Context context, DB db, long id, int sequence) throws IOException {
// Attachments of drafts might not have been uploaded yet
if (sequence > attachments.size()) {
Log.w("Attachment unavailable sequence=" + sequence + " size=" + attachments.size());
return;
return false;
}
// Get data
@ -662,10 +662,12 @@ public class MessageHelper {
db.attachment().setDownloaded(id, size);
Log.i("Downloaded attachment size=" + size);
return true;
} catch (Throwable ex) {
Log.w(ex);
// Reset progress on failure
db.attachment().setError(id, Helper.formatThrowable(ex));
return false;
} finally {
if (os != null)
os.close();

View File

@ -2638,7 +2638,8 @@ public class ServiceSynchronize extends LifecycleService {
EntityAttachment attachment = attachments.get(i);
if (!attachment.available)
if (!metered || (attachment.size != null && attachment.size < maxSize))
parts.downloadAttachment(context, db, attachment.id, attachment.sequence);
if (!parts.downloadAttachment(context, db, attachment.id, attachment.sequence))
break;
}
}
}