From 8d50dfd93c6d8d9fa282dfd9647556aa740bc4d0 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Wed, 10 Jul 2019 18:35:11 +0200 Subject: [PATCH] Fixed overwriting file in download mode Added prevention of copying itself to itself --- .../magisk/model/download/SubstrateDownloadService.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/download/SubstrateDownloadService.kt b/app/src/main/java/com/topjohnwu/magisk/model/download/SubstrateDownloadService.kt index 0ff327f2c..445a1b965 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/download/SubstrateDownloadService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/download/SubstrateDownloadService.kt @@ -22,6 +22,7 @@ import com.topjohnwu.superuser.ShellUtils import io.reactivex.Single import okhttp3.ResponseBody import org.koin.android.ext.android.inject +import timber.log.Timber import java.io.File import kotlin.random.Random.Default.nextInt @@ -51,7 +52,7 @@ abstract class SubstrateDownloadService : Service() { private fun start(subject: DownloadSubject) = search(subject) .onErrorResumeNext(download(subject)) .subscribeK { - runCatching { onFinished(it, subject) } + runCatching { onFinished(it, subject) }.onFailure { Timber.e(it) } finish(it, subject) } @@ -93,7 +94,10 @@ abstract class SubstrateDownloadService : Service() { protected fun moveToDownloads(file: File) { val destination = downloadsFile(file.name) - file.copyTo(destination) + if (file != destination) { + destination.deleteRecursively() + file.copyTo(destination) + } toast(getString(R.string.internal_storage, "/Download/${file.name}"), Toast.LENGTH_LONG) }