Skip to content

Commit

Permalink
fix: Import files can have a coroutine competition problem
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed May 3, 2024
1 parent f93e7e1 commit be85119
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ import com.infomaniak.drive.utils.getAvailableMemory
import com.infomaniak.drive.utils.showSnackbar
import com.infomaniak.lib.core.utils.getFileName
import io.sentry.Sentry
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.Date

class ImportFilesDialog : DialogFragment() {
Expand Down Expand Up @@ -82,21 +85,16 @@ class ImportFilesDialog : DialogFragment() {

private suspend fun importFiles() {
var errorCount = 0
val uploadFilesJobs = mutableListOf<Job>()
navArgs.uris.forEach { uri ->
uploadFilesJobs.add(lifecycleScope.launch {
runCatching {
initUpload(uri)
}.onFailure {
it.printStackTrace()
Sentry.captureException(it)

errorCount++
}
})
}
runCatching {
initUpload(uri)
}.onFailure {
it.printStackTrace()
Sentry.captureException(it)

uploadFilesJobs.joinAll()
errorCount++
}
}

if (errorCount > 0) {
withContext(Dispatchers.Main) {
Expand Down

0 comments on commit be85119

Please sign in to comment.