Fixed overwriting file in download mode
Added prevention of copying itself to itself
This commit is contained in:
parent
51e40dd98c
commit
8d50dfd93c
@ -22,6 +22,7 @@ import com.topjohnwu.superuser.ShellUtils
|
|||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.random.Random.Default.nextInt
|
import kotlin.random.Random.Default.nextInt
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ abstract class SubstrateDownloadService : Service() {
|
|||||||
private fun start(subject: DownloadSubject) = search(subject)
|
private fun start(subject: DownloadSubject) = search(subject)
|
||||||
.onErrorResumeNext(download(subject))
|
.onErrorResumeNext(download(subject))
|
||||||
.subscribeK {
|
.subscribeK {
|
||||||
runCatching { onFinished(it, subject) }
|
runCatching { onFinished(it, subject) }.onFailure { Timber.e(it) }
|
||||||
finish(it, subject)
|
finish(it, subject)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +94,10 @@ abstract class SubstrateDownloadService : Service() {
|
|||||||
|
|
||||||
protected fun moveToDownloads(file: File) {
|
protected fun moveToDownloads(file: File) {
|
||||||
val destination = downloadsFile(file.name)
|
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)
|
toast(getString(R.string.internal_storage, "/Download/${file.name}"), Toast.LENGTH_LONG)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user