Add more backup cancellation checks.

This commit is contained in:
Greyson Parrelli
2025-05-30 11:12:42 -04:00
committed by Cody Henthorne
parent 98e06081af
commit 3bd4e39093

View File

@@ -48,10 +48,6 @@ class BackupMessagesJob private constructor(
const val KEY = "BackupMessagesJob"
/**
* Pruning abandoned remote media is relatively expensive, so we should
* not do this every time we backup.
*/
fun enqueue() {
val jobManager = AppDependencies.jobManager
@@ -104,6 +100,10 @@ class BackupMessagesJob private constructor(
SignalDatabase.attachments.createKeyIvDigestForAttachmentsThatNeedArchiveUpload().takeIf { it > 0 }?.let { count -> Log.w(TAG, "Needed to create $count key/iv/digests.") }
stopwatch.split("key-iv-digest")
if (isCanceled) {
return Result.failure()
}
val (tempBackupFile, currentTime) = when (val generateBackupFileResult = getOrCreateBackupFile(stopwatch)) {
is BackupFileResult.Success -> generateBackupFileResult
BackupFileResult.Failure -> return Result.failure()
@@ -154,7 +154,11 @@ class BackupMessagesJob private constructor(
is NetworkResult.NetworkError -> {
Log.i(TAG, "Network failure", result.getCause())
return Result.retry(defaultBackoff())
return if (isCanceled) {
Result.failure()
} else {
Result.retry(defaultBackoff())
}
}
is NetworkResult.StatusCodeError -> {
@@ -186,7 +190,11 @@ class BackupMessagesJob private constructor(
stopwatch.split("used-space")
stopwatch.stop(TAG)
if (SignalStore.backup.backsUpMedia && SignalDatabase.attachments.doAnyAttachmentsNeedArchiveUpload() && !isCanceled) {
if (isCanceled) {
return Result.failure()
}
if (SignalStore.backup.backsUpMedia && SignalDatabase.attachments.doAnyAttachmentsNeedArchiveUpload()) {
Log.i(TAG, "Enqueuing attachment backfill job.")
AppDependencies.jobManager.add(ArchiveAttachmentBackfillJob())
} else {
@@ -224,6 +232,10 @@ class BackupMessagesJob private constructor(
writeMediaCursorToTemporaryTable(it, currentTime = currentTime, mediaBackupEnabled = SignalStore.backup.backsUpMedia)
}
if (isCanceled) {
return BackupFileResult.Failure
}
stopwatch.split("export")
when (val result = ArchiveValidator.validate(tempBackupFile, backupKey, forTransfer = false)) {