|
@@ -11,6 +11,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
|
|
|
import io.reactivex.disposables.Disposable
|
|
|
import io.reactivex.schedulers.Schedulers
|
|
|
import java.io.File
|
|
|
+import java.lang.Exception
|
|
|
|
|
|
class CopyFileViewModel(applicationContext: Context,
|
|
|
private val info: CopyFileInfo,
|
|
@@ -28,6 +29,7 @@ class CopyFileViewModel(applicationContext: Context,
|
|
|
private val mCopyProgressLiveData = MutableLiveData<Int>().apply { value = 0 }
|
|
|
|
|
|
private var copyFileDisposable: Disposable? = null
|
|
|
+ private var srcFilePath: String? = null
|
|
|
private var dstFilePath: String? = null
|
|
|
private var hasCompleteCopy = false
|
|
|
|
|
@@ -46,6 +48,7 @@ class CopyFileViewModel(applicationContext: Context,
|
|
|
} else {
|
|
|
null
|
|
|
}
|
|
|
+ srcFilePath = source?.getFilePath()
|
|
|
val fullFileSize = Math.max(1, source?.getFileSize() ?: 1)
|
|
|
val task = CopyFileTask()
|
|
|
task.setCopyMode(CopyFileTask.Mode.CREATE_NEW_FILE)
|
|
@@ -84,6 +87,11 @@ class CopyFileViewModel(applicationContext: Context,
|
|
|
|
|
|
private fun deleteDstFile() {
|
|
|
dstFilePath?.apply {
|
|
|
+ // do not delete the destination file if it is also the source file
|
|
|
+ try {
|
|
|
+ if (!srcFilePath.isNullOrEmpty() && File(srcFilePath).canonicalPath == File(dstFilePath).canonicalPath) return
|
|
|
+ } catch (e: Exception) {}
|
|
|
+
|
|
|
val file = File(this)
|
|
|
if (file.exists()) {
|
|
|
file.delete()
|